I am trying to add support for horizontal scrolling with the touchpad to my WPF application.
I am working on an HP laptop with a working touchpad: Under Windows -> Settings -> Touchpad it says "Your PC has a precision touchpad" and offers extensive options. The multiple finger gestures work, and two-finger swiping to scroll horizontally works on several apps that I tried; in short, the touchpad is perfectly capable of issuing multi-touch events.
Vertical scrolling and zooming already work thanks to some layer converting these touch events to mouse events, and this layer does also convert horizontal touch events to WM_MOUSEHWHEEL events, but WPF ignores those. There exists a feature request to add WM_MOUSEHWHEEL support to WPF here: https://github.com/dotnet/wpf/issues/3201 but it is currently assigned to nobody, and the year is 2023.
I have found this solution here: https://stackoverflow.com/a/47457389/773113 (also here: https://blog.walterlv.com/post/handle-horizontal-scrolling-of-touchpad-en.html) but it gets dirty with AddHook()
and WM_MOUSEHWHEEL
, so I have the following issues with it:
I find it hard to believe that one has to resort to such gimmicks in order to achieve something as simple and commonplace as receiving touchpad input.
These gimmicks have a strong windows-only smell to me, whereas in the future I see one of the following happening:
- Either Microsoft will release a cross-platform version of WPF to go with NetCore, so windows-specific gimmicks will be inapplicable, or
- I will switch from WPF to Avalonia, in which case, windows-specific gimmicks will, again, be inapplicable.
So, I would rather not use walterlv's solution if I can avoid it.
While looking for an alternative I stumbled upon the concept of "manipulation" in WPF, and I thought that this might do it, but as it turns out, this entire manipulation mechanism of WPF for some reason applies only to touchscreens, not touchpads, even though I can see no practical difference between the two.
- I found a tutorial (Microsoft Learn - .NET - Desktop Guide - Windows Presentation Foundation - Advanced - Walkthrough: Creating Your First Touch Application) and implemented it (https://github.com/mikenakis/WpfTest2) but it does not detect any touchpad events at all. I tried it with DotNet 7.0 and with DotNet Framework 4.7.2, "same difference." A previous question of mine was down-voted for the folly of expecting that "manipulation" applies to touchpads.
So, is there any way to support horizontal scrolling with the touchpad in my WPF application without resorting to WM_MOUSEHWHEEL
?