I need to access the pen pressure of windows stylus inputs similar to the libinput Tablet(Axis(_))-Event like I implemented here.
Since using libinput is a linux-specific library and doesn't work on windows, I tried using the RealTimeStylus-API using the windows-rs-crate.
After instanceating the com object with CoCreateInstance(&RealTimeStylus, None, CLSCTX_ALL), I ran into two issues:
- If I try to use the
SetHWND-Method to bind the window to the object, it needs a::windows_core::IntoParam<super::super::Foundation::HANDLE_PTR>, not a HWND. While compiling, I get the following error:
error[E0277]: the trait bound `HWND: CanInto<HANDLE_PTR>` is not satisfied
--> src\input\win_input_device.rs:43:40
|
43 | i_real_time_stylus.SetHWND(hwnd).unwrap();
| ------- ^^^^ the trait `CanInto<HANDLE_PTR>` is not implemented for `HWND`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `CanInto<T>`:
<Battery as CanInto<IUnknown>>
<Battery as CanInto<IInspectable>>
<windows::core::imp::IAgileObject as CanInto<IUnknown>>
<IAgileReference as CanInto<IUnknown>>
<BatteryReport as CanInto<IUnknown>>
<BatteryReport as CanInto<IInspectable>>
<windows::core::imp::IErrorInfo as CanInto<IUnknown>>
<ILowLevelDevicesAggregateProvider as CanInto<IUnknown>>
and 452 others
= note: required for `HWND` to implement `IntoParam<HANDLE_PTR, CopyType>`
note: required by a bound in `IRealTimeStylus::SetHWND`
--> C:\Users\***\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.51.1\src\Windows\Win32\UI\TabletPC\mod.rs:7079:13
|
7077 | pub unsafe fn SetHWND<P0>(&self, hwnd: P0) -> ::windows_core::Result<()>
| ------- required by a bound in this associated function
7078 | where
7079 | P0: ::windows_core::IntoParam<super::super::Foundation::HANDLE_PTR>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `IRealTimeStylus::SetHWND`
Trying to convert between the two types manually (i_real_time_stylus.SetHWND(HANDLE_PTR(hwnd.0 as _)).unwrap();) fails: The program just hangs indefinetly on the SetHWND Method.
- To access events, I'd need to register an input plugin using AddStylusSyncPlugin (or the async equivalent), but the required interface is only provided as a struct, not a trait to implement.
Is there an easier way to get the current pen pressure? What am I doing wrong?
EDIT: After trying to build a minimal reproducible example, I noticed that the first issue was just caused by the way I got to the hwnd object:
let hwnd = HWND(<Win32WindowHandle>.hwnd as isize);
if !unsafe { IsWindow(hwnd).into() } {
panic!("HWND is not a vaild window");
}
It works using GetActiveWindow. The second issue is still problematic...