Skip to main content

Python wrapper for Interception driver with hotkey support

Project description

PyInterceptor

PyInterceptor is a Python library for intercepting and manipulating keyboard and mouse inputs on Windows systems. It provides a high-level interface for working with keyboard and mouse events, including hotkey management and input simulation.

Features

  • Intercept keyboard and mouse inputs at the system level
  • Register and manage hotkeys with custom callbacks
  • Simulate keyboard and mouse inputs
  • Track the state of pressed keys
  • Filter specific types of input events
  • Support for both keyboard and mouse devices

Requirements

  • Windows operating system
  • Python 3.6+
  • Interception driver installed on the system

Installation

pip install pyinterceptor-hotkeys

Usage Examples

Basic Hotkey Registration

from pyinterceptor import HotkeyManager, Key, Device, KeyStroke


def on_hotkey_pressed(device: Device, stroke: KeyStroke, pressed_keys: set[Key]):
    print("Hotkey was pressed!")


# Create a hotkey manager for keyboard
hotkey_manager = HotkeyManager(keyboard=True)

# Register Ctrl+Shift+A as a hotkey
hotkey = hotkey_manager.register_hotkey([Key.LEFT_CTRL, Key.LEFT_SHIFT, Key.A], on_hotkey_pressed)

# Start listening for hotkeys
hotkey_manager.listen()

# To unregister a hotkey
# hotkey_manager.unregister_hotkey(hotkey)

Simulating Keyboard Input

from pyinterceptor import Keyboard, Key

# Create a keyboard instance (device ID 1)
keyboard = Keyboard(device=1)

# Simulate pressing and releasing the 'A' key
keyboard.tap(Key.A)

# Press a key
keyboard.press(Key.B)

# Release a key
keyboard.release(Key.B)

Intercepting Input Events

from pyinterceptor import Interception

# Get the singleton instance of Interception
interception = Interception()

# Set up a filter for keyboard events
interception.set_filter_keyboard()


# Add an event listener
def input_callback(stroke):
    print(f"Key: {stroke.code}, State: {stroke.flags}")
    # Return True to suppress the input, False to let it through
    return False


interception.add_event_listener(input_callback)

# Main event loop
try:
    while True:
        # Wait for and process input events
        interception.receive()
except KeyboardInterrupt:
    # Clean up
    interception.close()

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

pyinterceptor_hotkeys-0.1.3.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

pyinterceptor_hotkeys-0.1.3-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file pyinterceptor_hotkeys-0.1.3.tar.gz.

File metadata

  • Download URL: pyinterceptor_hotkeys-0.1.3.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pyinterceptor_hotkeys-0.1.3.tar.gz
Algorithm Hash digest
SHA256 23c9f8c77f93a2d4b354a79c9cf872e582b6fd11bf4bb2f476ea51c7116a1f09
MD5 2c6ae3310201313d8fcb0a78173128b6
BLAKE2b-256 2192dfce61282f8db73eab34d286385f3d7b7990336cf6bffd63a169fdc54a96

See more details on using hashes here.

File details

Details for the file pyinterceptor_hotkeys-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pyinterceptor_hotkeys-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 929c1f5d72c95f596cba48390fd8c4869390e0acd064ed355162b73a86b6ce71
MD5 12b2214cecb915d080d9c1d8ea5c1c57
BLAKE2b-256 c6e6e0fd4ec7ff9fddaaeec413de85204a10af32fa7b811beaec006fabc743b1

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