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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyinterceptor_hotkeys-0.1.1.tar.gz
  • Upload date:
  • Size: 19.5 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.1.tar.gz
Algorithm Hash digest
SHA256 edbe5d477df99bb4211d40413b8f4030fcecdf83019b57342b34b29cb518c087
MD5 45e0049c6046b8aafd43a5fc6eebb8b0
BLAKE2b-256 36ef5ad1285e10d8cceb585d47f21062913bcd2eb9b9ac165d2ea2d34f4274fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyinterceptor_hotkeys-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e88fd0fbb84bc00396a46235261a4fabaf88212ed84b169e21057e2c80ee255
MD5 5897f4465e71cb53ee169ed3d13bd24e
BLAKE2b-256 42b4cb6ba59675a2942a00215bb3dd7fd07e41a97563bef819562937f6d4be7d

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