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.1.tar.gz (26.7 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.1-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

Details for the file windows_trackpad_helper-1.0.1.tar.gz.

File metadata

  • Download URL: windows_trackpad_helper-1.0.1.tar.gz
  • Upload date:
  • Size: 26.7 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.1.tar.gz
Algorithm Hash digest
SHA256 b8845cb282318b209630b37be5914bcbb5a3a5ecd8a1b58dbf1f421709b20387
MD5 23542d9d25aee4f021c61e603a5b34ba
BLAKE2b-256 3ff1f3c31be84c59924c64adbb5314689b75cfb6e214f7b97f6283f74780d736

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for windows_trackpad_helper-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33084058b9b1870b2469ea6b838c2793eb8dd5a573370a4b68aac81421efd21b
MD5 e276c5ca4ee2bc9e1948b976a39c0521
BLAKE2b-256 ae352bb4faa99eac26eec175ad33d55952ac5a94bf6efc394b566e2f59f28058

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