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.2.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.2-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyinterceptor_hotkeys-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 5e380d47c64977d8903c0795b4356db5f0abc46175a0bedea99d1bd249dd298e
MD5 bad2f12e14918e56026972c84f961aa6
BLAKE2b-256 fbd92bcf49a1ad245a0cdefc54e29ed993c1d42315a56280eaec23be734cbd3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyinterceptor_hotkeys-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6b9d617ee92ba0f02a953c0c445b7aa057b6443c5b82c36c0f5d18df63c6e81a
MD5 3b21069e05f3e3c3b2b5faf917c425f8
BLAKE2b-256 bf7741ac8d1152496e53f6949a9d28b49567856dd0ae93df035ee4212561d974

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