Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Major rework, a lot more intuitive and user friendly! #11

Open
wants to merge 44 commits into
base: master
Choose a base branch
from

Conversation

kennyhml
Copy link

Hey!

So, I needed to look into "real" inputs for some of my own projects. Eventually I learned about interception and found this python port for it, but honestly, I found it really hard to figure out how to use it with the provided code and examples, so I decided to spend some time on making it more intuitive, cleaner and more pythonic.

Major changes:

  • Split things apart into their own modules, everything is currently cramped into the interception.py module
  • Turned strokes into more suitable class types
  • Added typing for the most part
  • Added pre-defined keycodes
  • Rearranged the consts to be more intuitive, using IntEnum
  • consts and keycodes are now meant for internal use, the "API" usage is defined by inputs.py
  • inputs.py is meant to operate just like pyautogui or pydirectinput would, so you can:
    • pass coordinates normally and they are converted to the "interception coordinates"
    • press keys by actual name ref, like press("w") instead of creating a KeyStroke with the code
    • Added context managed functions like hold_mouse and hold_key to be used in a with context
    • Added relative mouse movement
    • Added many optional specification for inputs (presses, intervals, delays, different types of passing coordinates)
    • Added listen_to_keyboard() and listen_to_mouse() to grab ur device numbers respectively

Stuff I'd like to add in the future:

  • Find a way to respect keyboard layouts, since it uses scan codes, on QWERTY keyboards it will press Z instead of Y
  • Add helpers such as setting up or uninstalling interception
  • Improve the documentation

Hope the rework is to your liking, I think it would help alot of people if it was more friendly to use, thanks alot for providing the base to this port!

@cobrce
Copy link
Owner

cobrce commented Apr 17, 2023

Hi, thanks for giving interest to this project.

I started this port as a pet project to learn more about interacting with system APIs, which explains the not so pythonic code xD.

Speaking of debugging the code, I had the same issue with the original C program where the computer becomes locked (I had to restart the computer several times), and I don't know what to do to avoid this, the only way to mitigate this is hooking either keyboard or mouse, not both.

Anyway, thank you for improvement, I appreciate the effort put into that, the code is acceptable, I just put some comments on the readme lines that need to be fixed to avoid confusion.

@kennyhml
Copy link
Author

kennyhml commented Apr 17, 2023

Hey, thanks for taking a look.

I personally have only been "locked out" from my inputs whenever an error occurred and I was running my IDE in debug mode, which caused the program to stall rather than terminate, thus inputs were still being intercepted but not relayed so to speak.

The main problem causing the errors was the one I explained in issue #12, specifically when moving the mouse around. Since that change I havent had any problems no matter what I used it for.

I just put some comments on the readme lines that need to be fixed to avoid confusion

Maybe im being an idiot but im unable to locate these comments, also yea I never intended to create a PR to this at first because honestly, didnt even expect it would be reviewed haha. So the readme is sorta irrelevant now

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants