Skip to main content

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:

  1. is_finger_down(system_id: int = 0):
    • When system_id is non-zero (specific device): Returns 1 if raw touchpad contact is active, 0 if inactive (and is a precision touchpad), or -1 if the state is unknown (e.g. non-precision device).
    • When system_id is 0 (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 (default 10000 ms).
      • -1 (Unknown): Raw touch is inactive and occurred outside the window (or never touched / non-precision device).
  2. get_time_since_last_touch(system_id: int = 0): Returns the precise milliseconds since the last physical contact occurred (-1 if never touched).
  3. set_lift_threshold(threshold_ms: int): Configures the time window (in milliseconds) used by global queries to distinguish between Lifted (0) and Unknown/Idle (-1) states.
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

windows_trackpad_helper-1.0.0.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

windows_trackpad_helper-1.0.0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

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

Hashes for windows_trackpad_helper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fc73929ecb39da03b9edca6cb8ac9e5e263e1a1db4f3cc94fcb086652e7f7652
MD5 abd45eef2458835a90f7dc628d11f5ff
BLAKE2b-256 041ce9a9cc5dec075841d18fd2dde8cc49d9ea841399b287df85709ead486a30

See more details on using hashes here.

File details

Details for the file windows_trackpad_helper-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for windows_trackpad_helper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9fc0879fd4f6fbce8b65d24fa817991c865862010bc0e8a8debb01329dca7a7
MD5 fab5c58fec0f1e79bda403547656d41f
BLAKE2b-256 f468112206bd5e33cf0603d9ac1a2e18f496c70de614b487248923ddb075f42e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page