pydirectinput-rgx


Namepydirectinput-rgx JSON
Version 2.1.1 PyPI version JSON
download
home_page
SummaryPython mouse and keyboard input automation for Windows using Direct Input.
upload_time2024-01-05 15:49:13
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT
keywords python directinput wrapper abstraction input gui automation
VCS
bugtrack_url
requirements typing-extensions
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pydirectinput_rgx

[![PyPI version](https://badge.fury.io/py/pydirectinput-rgx.svg)](https://badge.fury.io/py/pydirectinput-rgx)

Simple docstring-based documentation available here: https://reggx.github.io/pydirectinput_rgx/

---

This library is a fork of https://github.com/learncodebygaming/pydirectinput 1.0.4

This package extends PyDirectInput in multiple ways. It fixes some bugs, adds the remaining missing input functions that still required using PyAutoGUI and provides additional keyword-only arguments to give more precise control over function behavior.

Contrary to the upstream PyDirectInput package, this package intends to replace PyAutoGUI almost completely for basic usage, skipping more advanced options like logging screenshots. This should reduce the need to install both PyDirectInput and PyAutoGUI side-by-side and thereby keep the number of dependencies to a minimum.

This library is fully in-line type-annotated and passes `mypy --strict`. Unfortunately, that also means this package **only works on Python 3.7 or higher**. There are **no** plans to backport changes to older versions.

This is why this package is available standalone and uses the same package name. There's no reason to use both side-by-side. Once Python's type annotations have reached wider adoption, this package may be merged back and integrated upstream. Until that moment, this package exists to fill that gap.

## Okay, but what is PyDirectInput in the first place?

PyDirectInput exists because PyAutoGUI uses older and less compatible API functions.

In order to increase compatibility with DirectX software and games, the internals have been replaced with SendInput() and Scan Codes instead of Virtual Key Codes.

For more information, see the original README at https://github.com/learncodebygaming/pydirectinput


## Installation

`pip install pydirectinput-rgx`

Alternatively, you can manually download the wheels from PyPI:
https://pypi.org/project/pydirectinput-rgx/

## Example Usage

```python
import pydirectinput

pydirectinput.moveTo(100, 150) # Move the mouse to the x, y coordinates 100, 150.

pydirectinput.click() # Click the mouse at its current location.

pydirectinput.click(button=pydirectinput.MOUSE_PRIMARY) # Click the mouse at its current location using the primary mouse button (will detect swapped mouse buttons and press accordingly).

pydirectinput.rightClick(200, 220) # Right-click the mouse at the x, y coordinates 200, 220.

pydirectinput.moveRel(None, 10)  # Move mouse 10 pixels down, that is, move the mouse relative to its current position.

pydirectinput.doubleClick() # Double click the mouse at the current location.

pydirectinput.moveTo(500, 500, duration=2) # Move mouse over 2 seconds.

pydirectinput.moveTo(1000, 250, attempt_pixel_perfect=True) # Sometimes Windows will not move the mouse to the exact pixel you specify. If you set attempt_pixel_perfect to True, PyDirectInput will attempt to move the mouse to the exact pixel you specify.

pydirectinput.moveRel(yOffset=-100, relative=True, disable_mouse_acceleration=True) # Move mouse 100 pixels up, disable mouse acceleration for this move. Mouse acceleration is messing with your mouse movements, so the library can disable it for you and restore your own settings after the movement is finished.

pydirectinput.dragTo(100, 200, button='left') # Drag mouse to the x, y coordinates 100, 200 while holding down the left mouse button.

pydirectinput.dragRel(0, 10, relative=True) # Drag mouse 10 pixels down, that is, drag mouse relative to its current position.

pydirectinput.scroll(10) # Scroll mouse 10 "clicks" up, that is, move the mouse wheel up.

pydirectinput.hscroll(10) # Scroll mouse 10 "clicks" to the right, that is, move the mouse wheel to the right. Support for this scolling method is very limited in most applications.

pydirectinput.keyDown('alt') # Simulate pressing dwon the Alt key.

pydirectinput.keyUp('alt') # Simulate releasing the Alt key.

pydirectinput.press('A', auto_shift=True) # Simulate pressing the A key, automatically holding down the Shift key if needed.

pydirectinput.press(['a', 'b'], presses=2, interval=1.0, delay=0.5, duration=0.25) # Simulate pressing the A and B keys twice in succesion, with pauses in between:
# A down
# 0.25 seconds pause (duration of key press)
# A up
# 0.5 seconds pause (delay between key presses)
# B down
# 0.25 seconds pause
# B up
# 1.0 seconds pause (interval between key press sequences)
# A down
# 0.25 seconds pause
# A up
# 0.5 seconds pause
# B down
# 0.25 seconds pause
# B up

try:
  with pydirectinput.hold('alt', raise_on_failure=True):
      pydirectinput.press('tab') # Simulate pressing the Alt-Tab hotkey combination.
except pydirectinput.PriorInputFailedException:
  print('Prior input failed, so this input was not sent.')

pydirectinput.hotkey('ctrl', 'v') # Simulate pressing the Ctrl-V hotkey combination.

pydirectinput.typewrite('Hello world!', interval=0.25) # Simulate typing the string 'Hello world!' with a 0.25 second pause in between each key press.

# By default, pydirectinput have an artifical pause after every action to make input look less robotic.
# You can disable the pause on a per-function basis by passing in _pause=False, e.g
pydirectinput.moveTo(100, 150, _pause=False)

# The duration of the automatic pause is determinded by the PAUSE constant, which is 0.01 seconds by default, but can be adjusted to other values if desired.
pydirectinput.PAUSE = 0.1 # Set the pause to 0.1 seconds.

# You can also disable the pause globally by setting the PAUSE constant to None.
pydirectinput.PAUSE = None # Disable the pause entirely.

# You can also unicode_* variants of the keyboard functions to type unicode characters. Support may be limited in some applications.
pydirectinput.unicode_press('👍')

# On the other hand, if you already know the scancode of the key you want to press, you can use the scancode_* variants of the keyboard functions.
pydirectinput.scancode_press(0x3B) # Press the F1 key.
```

## Provided functions with same/similar signature to PyAutoGui:

* Informational:
  - `position()`
  - `size()`
  - `on_primary_monitor()` / `onScreen()`
  - `valid_screen_coordinates()`
  - `is_valid_key()` / `isValidKey()`
* Mouse input:
  - `moveTo()`
  - `move()` / `moveRel()`
  - `mouseDown()`
  - `mouseUp()`
  - `click()` and derivatives:
    - `leftClick()`
    - `rightClick()`
    - `middleClick()`
    - `doubleClick()`
    - `tripleClick()`
  - `scroll()` / `vscroll()`
  - `hscroll()`
  - `dragTo()`
  - `drag()` / `dragRel()`
* Keyboard input:
  - `keyDown()`
  - `keyUp()`
  - `press()`
  - `hold()` (supports context manager)
  - `write()` / `typewrite()`
  - `hotkey()`


### Additionally, keyboard input has been extended with :
* low-level scancode_* functions that allow integer scancode as arguments:
  - `scancode_keyDown()`
  - `scancode_keyUp()`
  - `scancode_press()`
  - `scancode_hold()` (supports context manager)
  - `scancode_hotkey()`
* higher-level unicode_* functions that allow inserting Unicode characters into supported programs:
  - `unicode_charDown()`
  - `unicode_charUp()`
  - `unicode_press()`
  - `unicode_hold()` (supports context manager)
  - `unicode_write()` / `unicode_typewrite()`
  - `unicode_hotkey()`


## Missing features compared to PyAutoGUI

- `logScreenshot` arguments. No screenshots will be created.

___

### Changelog compared to forked origin point PyDirectInput version 1.0.4:

* Adding/fixing extended key codes
* Adding flake8 linting
* Adding mypy type hinting and adding annotations (**This makes this fork Python >=3.7 only!**)
* Adding scroll functions based on [learncodebygaming/PR #22](https://github.com/learncodebygaming/pydirectinput/pull/22) and improve them
* Adding hotkey functions based on [learncodebygaming/PR #30](https://github.com/learncodebygaming/pydirectinput/pull/30) and improve them
* Adding more available keyboard keys
* Adding optional automatic shifting for certain keayboard keys in old down/up/press functions
* Adding additional arguments for tighter timing control for press and typewrite functions
* Adding Unicode input functions that allow sending text that couldn't be sent by simple keyboard
* Adding Scancode input functions that allow lower level access to SendInput's abstractions
* Adding support for multi-monitor setups via virtual resolution (most functions should work without just fine)
* Adding support for swapped primary mouse buttons
* Adding duration support for mouse functions
* Adding sleep calibration for mouse duration
* Adding automatic disabling of mouse acceleration for more accurate relative mouse movement
* Increase documentation
* Improve performance of _genericPyDirectInputChecks decorator (Thanks Agade09 for [reggx/PR #1](https://github.com/ReggX/pydirectinput_rgx/pull/1) and [reggx/PR #2](https://github.com/ReggX/pydirectinput_rgx/pull/2))

**This library uses in-line type annotations that require at least Python version 3.7 or higher and there are no plans to make the code backwards compatible to older Python versions!**


___
See [pydirectinput's original README](OLD_README.md).
___

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pydirectinput-rgx",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "python,directinput,wrapper,abstraction,input,gui,automation",
    "author": "",
    "author_email": "ReggX <dev@reggx.eu>",
    "download_url": "https://files.pythonhosted.org/packages/b3/c7/fe4f8e87d8cd14e7408b51362ee8769e45649ab342c1555a7d8062c440e9/pydirectinput_rgx-2.1.1.tar.gz",
    "platform": null,
    "description": "# pydirectinput_rgx\r\n\r\n[![PyPI version](https://badge.fury.io/py/pydirectinput-rgx.svg)](https://badge.fury.io/py/pydirectinput-rgx)\r\n\r\nSimple docstring-based documentation available here: https://reggx.github.io/pydirectinput_rgx/\r\n\r\n---\r\n\r\nThis library is a fork of https://github.com/learncodebygaming/pydirectinput 1.0.4\r\n\r\nThis package extends PyDirectInput in multiple ways. It fixes some bugs, adds the remaining missing input functions that still required using PyAutoGUI and provides additional keyword-only arguments to give more precise control over function behavior.\r\n\r\nContrary to the upstream PyDirectInput package, this package intends to replace PyAutoGUI almost completely for basic usage, skipping more advanced options like logging screenshots. This should reduce the need to install both PyDirectInput and PyAutoGUI side-by-side and thereby keep the number of dependencies to a minimum.\r\n\r\nThis library is fully in-line type-annotated and passes `mypy --strict`. Unfortunately, that also means this package **only works on Python 3.7 or higher**. There are **no** plans to backport changes to older versions.\r\n\r\nThis is why this package is available standalone and uses the same package name. There's no reason to use both side-by-side. Once Python's type annotations have reached wider adoption, this package may be merged back and integrated upstream. Until that moment, this package exists to fill that gap.\r\n\r\n## Okay, but what is PyDirectInput in the first place?\r\n\r\nPyDirectInput exists because PyAutoGUI uses older and less compatible API functions.\r\n\r\nIn order to increase compatibility with DirectX software and games, the internals have been replaced with SendInput() and Scan Codes instead of Virtual Key Codes.\r\n\r\nFor more information, see the original README at https://github.com/learncodebygaming/pydirectinput\r\n\r\n\r\n## Installation\r\n\r\n`pip install pydirectinput-rgx`\r\n\r\nAlternatively, you can manually download the wheels from PyPI:\r\nhttps://pypi.org/project/pydirectinput-rgx/\r\n\r\n## Example Usage\r\n\r\n```python\r\nimport pydirectinput\r\n\r\npydirectinput.moveTo(100, 150) # Move the mouse to the x, y coordinates 100, 150.\r\n\r\npydirectinput.click() # Click the mouse at its current location.\r\n\r\npydirectinput.click(button=pydirectinput.MOUSE_PRIMARY) # Click the mouse at its current location using the primary mouse button (will detect swapped mouse buttons and press accordingly).\r\n\r\npydirectinput.rightClick(200, 220) # Right-click the mouse at the x, y coordinates 200, 220.\r\n\r\npydirectinput.moveRel(None, 10)  # Move mouse 10 pixels down, that is, move the mouse relative to its current position.\r\n\r\npydirectinput.doubleClick() # Double click the mouse at the current location.\r\n\r\npydirectinput.moveTo(500, 500, duration=2) # Move mouse over 2 seconds.\r\n\r\npydirectinput.moveTo(1000, 250, attempt_pixel_perfect=True) # Sometimes Windows will not move the mouse to the exact pixel you specify. If you set attempt_pixel_perfect to True, PyDirectInput will attempt to move the mouse to the exact pixel you specify.\r\n\r\npydirectinput.moveRel(yOffset=-100, relative=True, disable_mouse_acceleration=True) # Move mouse 100 pixels up, disable mouse acceleration for this move. Mouse acceleration is messing with your mouse movements, so the library can disable it for you and restore your own settings after the movement is finished.\r\n\r\npydirectinput.dragTo(100, 200, button='left') # Drag mouse to the x, y coordinates 100, 200 while holding down the left mouse button.\r\n\r\npydirectinput.dragRel(0, 10, relative=True) # Drag mouse 10 pixels down, that is, drag mouse relative to its current position.\r\n\r\npydirectinput.scroll(10) # Scroll mouse 10 \"clicks\" up, that is, move the mouse wheel up.\r\n\r\npydirectinput.hscroll(10) # Scroll mouse 10 \"clicks\" to the right, that is, move the mouse wheel to the right. Support for this scolling method is very limited in most applications.\r\n\r\npydirectinput.keyDown('alt') # Simulate pressing dwon the Alt key.\r\n\r\npydirectinput.keyUp('alt') # Simulate releasing the Alt key.\r\n\r\npydirectinput.press('A', auto_shift=True) # Simulate pressing the A key, automatically holding down the Shift key if needed.\r\n\r\npydirectinput.press(['a', 'b'], presses=2, interval=1.0, delay=0.5, duration=0.25) # Simulate pressing the A and B keys twice in succesion, with pauses in between:\r\n# A down\r\n# 0.25 seconds pause (duration of key press)\r\n# A up\r\n# 0.5 seconds pause (delay between key presses)\r\n# B down\r\n# 0.25 seconds pause\r\n# B up\r\n# 1.0 seconds pause (interval between key press sequences)\r\n# A down\r\n# 0.25 seconds pause\r\n# A up\r\n# 0.5 seconds pause\r\n# B down\r\n# 0.25 seconds pause\r\n# B up\r\n\r\ntry:\r\n  with pydirectinput.hold('alt', raise_on_failure=True):\r\n      pydirectinput.press('tab') # Simulate pressing the Alt-Tab hotkey combination.\r\nexcept pydirectinput.PriorInputFailedException:\r\n  print('Prior input failed, so this input was not sent.')\r\n\r\npydirectinput.hotkey('ctrl', 'v') # Simulate pressing the Ctrl-V hotkey combination.\r\n\r\npydirectinput.typewrite('Hello world!', interval=0.25) # Simulate typing the string 'Hello world!' with a 0.25 second pause in between each key press.\r\n\r\n# By default, pydirectinput have an artifical pause after every action to make input look less robotic.\r\n# You can disable the pause on a per-function basis by passing in _pause=False, e.g\r\npydirectinput.moveTo(100, 150, _pause=False)\r\n\r\n# The duration of the automatic pause is determinded by the PAUSE constant, which is 0.01 seconds by default, but can be adjusted to other values if desired.\r\npydirectinput.PAUSE = 0.1 # Set the pause to 0.1 seconds.\r\n\r\n# You can also disable the pause globally by setting the PAUSE constant to None.\r\npydirectinput.PAUSE = None # Disable the pause entirely.\r\n\r\n# You can also unicode_* variants of the keyboard functions to type unicode characters. Support may be limited in some applications.\r\npydirectinput.unicode_press('\ud83d\udc4d')\r\n\r\n# On the other hand, if you already know the scancode of the key you want to press, you can use the scancode_* variants of the keyboard functions.\r\npydirectinput.scancode_press(0x3B) # Press the F1 key.\r\n```\r\n\r\n## Provided functions with same/similar signature to PyAutoGui:\r\n\r\n* Informational:\r\n  - `position()`\r\n  - `size()`\r\n  - `on_primary_monitor()` / `onScreen()`\r\n  - `valid_screen_coordinates()`\r\n  - `is_valid_key()` / `isValidKey()`\r\n* Mouse input:\r\n  - `moveTo()`\r\n  - `move()` / `moveRel()`\r\n  - `mouseDown()`\r\n  - `mouseUp()`\r\n  - `click()` and derivatives:\r\n    - `leftClick()`\r\n    - `rightClick()`\r\n    - `middleClick()`\r\n    - `doubleClick()`\r\n    - `tripleClick()`\r\n  - `scroll()` / `vscroll()`\r\n  - `hscroll()`\r\n  - `dragTo()`\r\n  - `drag()` / `dragRel()`\r\n* Keyboard input:\r\n  - `keyDown()`\r\n  - `keyUp()`\r\n  - `press()`\r\n  - `hold()` (supports context manager)\r\n  - `write()` / `typewrite()`\r\n  - `hotkey()`\r\n\r\n\r\n### Additionally, keyboard input has been extended with :\r\n* low-level scancode_* functions that allow integer scancode as arguments:\r\n  - `scancode_keyDown()`\r\n  - `scancode_keyUp()`\r\n  - `scancode_press()`\r\n  - `scancode_hold()` (supports context manager)\r\n  - `scancode_hotkey()`\r\n* higher-level unicode_* functions that allow inserting Unicode characters into supported programs:\r\n  - `unicode_charDown()`\r\n  - `unicode_charUp()`\r\n  - `unicode_press()`\r\n  - `unicode_hold()` (supports context manager)\r\n  - `unicode_write()` / `unicode_typewrite()`\r\n  - `unicode_hotkey()`\r\n\r\n\r\n## Missing features compared to PyAutoGUI\r\n\r\n- `logScreenshot` arguments. No screenshots will be created.\r\n\r\n___\r\n\r\n### Changelog compared to forked origin point PyDirectInput version 1.0.4:\r\n\r\n* Adding/fixing extended key codes\r\n* Adding flake8 linting\r\n* Adding mypy type hinting and adding annotations (**This makes this fork Python >=3.7 only!**)\r\n* Adding scroll functions based on [learncodebygaming/PR #22](https://github.com/learncodebygaming/pydirectinput/pull/22) and improve them\r\n* Adding hotkey functions based on [learncodebygaming/PR #30](https://github.com/learncodebygaming/pydirectinput/pull/30) and improve them\r\n* Adding more available keyboard keys\r\n* Adding optional automatic shifting for certain keayboard keys in old down/up/press functions\r\n* Adding additional arguments for tighter timing control for press and typewrite functions\r\n* Adding Unicode input functions that allow sending text that couldn't be sent by simple keyboard\r\n* Adding Scancode input functions that allow lower level access to SendInput's abstractions\r\n* Adding support for multi-monitor setups via virtual resolution (most functions should work without just fine)\r\n* Adding support for swapped primary mouse buttons\r\n* Adding duration support for mouse functions\r\n* Adding sleep calibration for mouse duration\r\n* Adding automatic disabling of mouse acceleration for more accurate relative mouse movement\r\n* Increase documentation\r\n* Improve performance of _genericPyDirectInputChecks decorator (Thanks Agade09 for [reggx/PR #1](https://github.com/ReggX/pydirectinput_rgx/pull/1) and [reggx/PR #2](https://github.com/ReggX/pydirectinput_rgx/pull/2))\r\n\r\n**This library uses in-line type annotations that require at least Python version 3.7 or higher and there are no plans to make the code backwards compatible to older Python versions!**\r\n\r\n\r\n___\r\nSee [pydirectinput's original README](OLD_README.md).\r\n___\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python mouse and keyboard input automation for Windows using Direct Input.",
    "version": "2.1.1",
    "project_urls": {
        "Homepage": "https://github.com/reggx/pydirectinput_rgx"
    },
    "split_keywords": [
        "python",
        "directinput",
        "wrapper",
        "abstraction",
        "input",
        "gui",
        "automation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "47b0b684abbed1c0f1ace6bb684ee804851233fcc7077244f88347e3a42f449a",
                "md5": "80a30db098be17ef50ca116a1360c30a",
                "sha256": "9a85fae82d739e8394863faee0c035324e590211011339390fc99864aa451d7e"
            },
            "downloads": -1,
            "filename": "pydirectinput_rgx-2.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "80a30db098be17ef50ca116a1360c30a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 35500,
            "upload_time": "2024-01-05T15:49:10",
            "upload_time_iso_8601": "2024-01-05T15:49:10.964415Z",
            "url": "https://files.pythonhosted.org/packages/47/b0/b684abbed1c0f1ace6bb684ee804851233fcc7077244f88347e3a42f449a/pydirectinput_rgx-2.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b3c7fe4f8e87d8cd14e7408b51362ee8769e45649ab342c1555a7d8062c440e9",
                "md5": "2e720363f2c1427f817d313e6e7655d8",
                "sha256": "5f87ff914d198c154969216c4a003662791c5e552697d211ddf560fbb464bb21"
            },
            "downloads": -1,
            "filename": "pydirectinput_rgx-2.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2e720363f2c1427f817d313e6e7655d8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 38996,
            "upload_time": "2024-01-05T15:49:13",
            "upload_time_iso_8601": "2024-01-05T15:49:13.218466Z",
            "url": "https://files.pythonhosted.org/packages/b3/c7/fe4f8e87d8cd14e7408b51362ee8769e45649ab342c1555a7d8062c440e9/pydirectinput_rgx-2.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-05 15:49:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "reggx",
    "github_project": "pydirectinput_rgx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "typing-extensions",
            "specs": [
                [
                    ">=",
                    "4.2.0"
                ]
            ]
        }
    ],
    "lcname": "pydirectinput-rgx"
}
        
Elapsed time: 0.16147s