A native C++ and Python helper for Windows to detect trackpad scrolling with accurate physical touch state.
Project description
Windows Trackpad Helper
A small Windows library to help python applications track finger state on precision trackpads, that may not be exposed otherwise. This allows, for example, PyQt apps to know if the trackpad is providing events after the user has lifted their fingers. This is needed because even though the device and the drivers provide this info, it may not trickle down to a framework like Qt.
It interacts directly with the Windows API via ctypes (included in the Python standard library) and can hook any native Win32 window handle (HWND). While the demo uses PyQt6, the library should work with any GUI framework that exposes an HWND handle (such as PySide6, wxPython, Tkinter, GLFW, SDL2, or raw Win32 windows).
Touch Tracking Algorithm & Heuristics
The library hooks Windows Raw Input (WM_INPUT messages for Digitizer/Touchpad usage pages) to track physical touchpad contact:
is_finger_down(system_id: int = 0):- When
system_idis non-zero (specific device): Returns1if raw touchpad contact is active,0if inactive (and is a precision touchpad), or-1if the state is unknown (e.g. non-precision device). - When
system_idis0(global/default): Employs the time heuristic and returns:1(Touching): Raw touchpad touch contact is active.0(Lifted): Raw contact is inactive, but a touch occurred within the lift threshold window (default10000ms).-1(Unknown): Raw touch is inactive and occurred outside the window (or never touched / non-precision device).
- When
get_time_since_last_touch(system_id: int = 0): Returns the precise milliseconds since the last physical contact occurred (-1if never touched).set_lift_threshold(threshold_ms: int): Configures the time window (in milliseconds) used by global queries to distinguish betweenLifted(0) andUnknown/Idle(-1) states.get_lift_threshold(): Returns the currently configured threshold in milliseconds.
Your application can query is_finger_down() inside its own scroll/wheel event loop to determine the physical finger state cleanly and simply.
Quick Start (Local Run)
To compile the DLL and run the dumper demo locally:
# 1. Compile the C++ DLL locally (requires MSVC or gcc & CMake)
build.bat
# 2. Install package locally in editable mode with optional demo dependencies
py -m pip install -e ".[demo]"
# 3. Run the dumper demo
python -m windows_trackpad_helper.demo_pyqt6
Direct Integration Example (Generic Win32)
from windows_trackpad_helper import TrackpadHelper
# 1. Initialize the helper
trackpad = TrackpadHelper()
# Explicitly configure the lift threshold window to 10 seconds
trackpad.set_lift_threshold(10000)
# 2. Hook your window using its native HWND handle (from Tkinter, wx, GLFW, etc.)
hwnd = my_window.window_id() # Replace with your framework's HWND getter
trackpad.init_hwnd(hwnd)
# ... inside your scroll/wheel event handler:
finger_state = trackpad.is_finger_down()
if finger_state == 1:
state_str = "Touching"
elif finger_state == 0:
state_str = "Lifted"
else:
state_str = "Unknown"
print(f"Physical Touch State: {state_str}")
# 3. Cleanly unhook on window close
trackpad.shutdown()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file windows_trackpad_helper-1.0.0.tar.gz.
File metadata
- Download URL: windows_trackpad_helper-1.0.0.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc73929ecb39da03b9edca6cb8ac9e5e263e1a1db4f3cc94fcb086652e7f7652
|
|
| MD5 |
abd45eef2458835a90f7dc628d11f5ff
|
|
| BLAKE2b-256 |
041ce9a9cc5dec075841d18fd2dde8cc49d9ea841399b287df85709ead486a30
|
File details
Details for the file windows_trackpad_helper-1.0.0-py3-none-any.whl.
File metadata
- Download URL: windows_trackpad_helper-1.0.0-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9fc0879fd4f6fbce8b65d24fa817991c865862010bc0e8a8debb01329dca7a7
|
|
| MD5 |
fab5c58fec0f1e79bda403547656d41f
|
|
| BLAKE2b-256 |
f468112206bd5e33cf0603d9ac1a2e18f496c70de614b487248923ddb075f42e
|