PyDirectInput Documentation

repository·master·Indexed 20 days ago

https://github.com/learncodebygaming/pydirectinput

A library that replicates PyAutoGUI's mouse and keyboard input functionality using DirectInput scan codes and the Win32 SendInput() function. It is designed as a drop-in replacement for PyAutoGUI to work with DirectX-based applications and video games that ignore standard Virtual Key Code (VK) inputs.

Tokens
626
Snippets
2
Records
4
Agent score
20%

What's inside PyDirectInput

  1. Install PyDirectInput via pip

    master

    Install the library using pip to enable DirectInput scan code and SendInput() based mouse and keyboard simulation. This is useful for applications (like video games) that rely on DirectX and may not respond to standard PyAutoGUI inputs.

    pip install pydirectinput
  2. Use PyDirectInput for mouse and keyboard inputs

    master

    PyDirectInput is designed to be a drop-in replacement for PyAutoGUI. It shares the same function interfaces, allowing you to substitute it into existing PyAutoGUI scripts where inputs are being ignored by DirectX-based software.

    Note: While the interfaces are the same, PyDirectInput may not implement all optional parameters (like duration, tween, or logScreenshot) found in PyAutoGUI.

    import pyautogui
    import pydirectinput
    
    # Mouse operations
    pydirectinput.moveTo(100, 150) # Move to absolute coordinates
    pydirectinput.click()         # Click at current location
    pydirectinput.click(200, 220) # Click at absolute coordinates
    pydirectinput.move(None, 10) # Move relative to current position (10 pixels down)
    pydirectinput.doubleClick()   # Double click
    
    # Keyboard operations
    pydirectinput.press('esc')    # Press a single key
    pydirectinput.keyDown('shift')
    pydirectinput.keyUp('shift')
  3. Limitations and unimplemented features in PyDirectInput

    master

    When using PyDirectInput, be aware of the following missing features compared to PyAutoGUI:

    Missing Functionality:

    • Scroll functions
    • Drag functions
    • Hotkey functions
    • Support for special characters requiring the shift key (e.g., !, @, #...)

    Ignored Parameters:

    • Mouse functions: duration, tween, logScreenshot are ignored.
    • Keyboard functions: logScreenshot is ignored.
  4. Implemented mouse and keyboard functions

    master

    The following functions are currently implemented in PyDirectInput:

    Mouse Functions:

    • position()
    • size()
    • moveTo(x, y)
    • move(x, y) / moveRel(x, y)
    • mouseDown()
    • mouseUp()
    • click()

    Keyboard Functions:

    • keyDown()
    • keyUp()
    • press()
    • write() / typewrite()

    General Features:

    • Fail Safe Check
    • Pause