/windows_pen_tablet_rust

Use rust to read pen pressure - demo of various methods

Primary LanguageJupyter Notebook

Rust Pen Tablet / Pen Display Input Capture

This workspace contains several crates (plus some extras, see further below) with different attempts to capture input from my Huion Kamvas Pro 24 Pen Display.

This repo was originally motivated because there was a problem with the windows ink functionality, and therefore the octotablet crate was not working for me. At the time, the only working option was Wintab32, so i spent a lot of time getting that working and ended up publishing the wintab_lite crate. Since then the driver issues have resolved, and all the various attempts below started working for me. Oh well, I learned a lot!

This repo just contains some examples for the various different ways I know to get pen tablet pressure on windows. I would probably recommend using octotablet as your first option through.

  1. test_windows_pointer_api (Works!)

  2. test_winit_with_octotablet (Works!)

    • Uses the octotablet crate to access pen events, but in a much more abstracted and idiomatic way. winit provides a much easier mechanisim to create a window.
    • octotablet currently provides access via the RealTimeStylus api which is documented as "Legacy User Interaction Features - ... Windows 7 and Earlier".
  3. test_wintab_lite_with_libloading (Works!)

  4. test_wintab_with_bindgen (Works - Terminal Output Only)

    • uses the wintab interface maintained by Wacom, using bindgen and libloading
    • clang must be installed and the LIBCLANG_PATH environment variable must be set
    • I have distributed the C headers listed below with this repo because I found them here under an MIT licence however please note that the headers themselves contain a copyright notice ¯\(ツ)/¯.
      • MSGPACK.H
      • PKTDEF.H
      • WINTAB.H
    • My code does not close the context properly, so beware potential issues. I was pleasantly supprised that i managed to get this option working at all!
  5. test_wintab_winit (Works)

    • Tests the types defined in wintab_lite by trying to use them with winit

Usage

For test_windows_pointer_api, test_winit_with_octotab and test_wintab_lite_libloading you will be able to draw in the window that appears

Screenshot

  • Mouse input will not draw anything
  • Space bar will clear the screen

NOTE: test_wintab_with_bindgen does not have the drawing code implemented!

Extra Packages

  • test_print_type_sizes contains python notebooks and experiments used to understand struct memory layout using the experimental compiler flag rustc -Z print-type-sizes
  • This little tool is probably worth splitting into its own repository in future, as it turned out to be quite handy.