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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
72c549f
initial reworks
kennyhml Apr 11, 2023
ccf46b2
added constants
kennyhml Apr 11, 2023
75faa06
turned strokes into dataclasses
kennyhml Apr 11, 2023
1e33e15
Update README.md
kennyhml Apr 11, 2023
d2c5889
added first api functions
kennyhml Apr 11, 2023
953ccb6
Merge branch 'master' of https://github.com/kennyhml/pyintercept
kennyhml Apr 11, 2023
c9bb4bc
added packaging
kennyhml Apr 11, 2023
d753d5b
added new clicks
kennyhml Apr 12, 2023
bdde0b3
updated gitignore
kennyhml Apr 12, 2023
75d3b44
updated gitignore
kennyhml Apr 12, 2023
dd64a17
added listener functions
kennyhml Apr 12, 2023
f2a1da0
Update README.md
kennyhml Apr 12, 2023
c73ff0e
added functions to capture devices
kennyhml Apr 12, 2023
5a4203b
Merge branch 'master' of https://github.com/kennyhml/pyintercept
kennyhml Apr 12, 2023
77095e7
improved input interception
kennyhml Apr 14, 2023
97484fe
changed input function
kennyhml Apr 14, 2023
b860cb5
fixed catching bad error
kennyhml Apr 14, 2023
3742965
fixed bad error
kennyhml Apr 14, 2023
dcae97b
use c_ubyte unsigned byte instead of c_byte
kennyhml Apr 15, 2023
b5f0c85
improved documentation of inputs
kennyhml Apr 17, 2023
cde53cc
added keyboard layout adjustment
kennyhml May 4, 2023
6a383fb
created utils and exceptions
kennyhml May 18, 2023
8f50c51
added global delays
kennyhml May 22, 2023
903a036
Update README.md
kennyhml May 27, 2023
e3dfd1c
Update README.md
kennyhml May 27, 2023
d49ab5f
Update README.md
kennyhml May 27, 2023
e5156f2
fixed scrolling
kennyhml May 27, 2023
d613c33
Merge branch 'master' of https://github.com/kennyhml/pyintercept
kennyhml May 27, 2023
1efb8ca
Add files via upload
dvdco Jun 1, 2023
a598a14
finishing touches
kennyhml Jun 1, 2023
8eaf2e5
changed scroll function back
kennyhml Jun 1, 2023
61ac50c
Merge pull request #3 from dvdco/master
kennyhml Jun 1, 2023
069e003
Update README.md
southwestfrance Jun 3, 2023
f8a6f58
Merge pull request #6 from southwestfrance/patch-1
kennyhml Jun 3, 2023
34f05db
improved documentation of move_to function
kennyhml Aug 13, 2023
255054b
Merge branch 'master' of https://github.com/kennyhml/pyintercept
kennyhml Aug 13, 2023
2198fa1
fixed keycodes mapped inproperly
kennyhml Aug 13, 2023
334f5c9
did some refactoring
kennyhml Aug 13, 2023
cfdd6e0
Update README.md
kennyhml Aug 13, 2023
09f13ad
Update README.md
kennyhml Aug 13, 2023
e3a5acc
auto capture & improvements
kennyhml Aug 15, 2023
b278ef2
Update README.md
kennyhml Aug 15, 2023
ab2fafb
added requires_driver to set_devices
kennyhml Aug 17, 2023
88b8fa7
Merge branch 'master' of https://github.com/kennyhml/pyintercept
kennyhml Aug 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.user
*.userosscache
*.sln.docstates
test

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down Expand Up @@ -328,3 +329,131 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
95 changes: 76 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,85 @@
# interception_py
This is a port (not a [wrapper][wrp]) of [interception][c_ception] dll to python, it communicates directly with interception's driver
# pyinterception
This is a greatly reworked version of [interception_py][wrp], a python port for [interception][c_ception], which is now obsolete and points here instead.

### why not using the wrapper?
* it's very slow and some strokes are lost
* fast strokes made python crash (some heap allocation errors)
The Interception API aims to build a portable programming interface that allows one to intercept and control a range of input devices.

To make it run you should install the driver from [c-interception][c_ception]
## How to install
Pyinterception is now available on PyPi under the name `interception-python`! So simply `pip install interception-python`.


## Why use interception?
Did you ever try to send inputs to an application or game and, well, nothing happened? Sure, in alot of cases this is resolved by running your
code with administrative privileges, but this is not always the case.

Take parsec as example, you are entirely unable to send any simulated inputs to parsec, but it has no problems with real inputs, so why is this?

Long story short, injected inputs actually have a `LowLevelKeyHookInjected` (0x10) flag. This flag will **always** be set when sending an Input with `SendInput` or the even older `mouse_event` and `keyb_event`. This flag is not at all hard to pick up for programs, if you have python3.7 and pyHook installed, you can try it yourself using this code:

### example
```py
import pyHook
import pythoncom

def keyb_event(event):

if event.flags & 0x10:
print("Injected input sent")
else:
print("Real input sent")

return True

hm = pyHook.HookManager()
hm.KeyDown = keyb_event

hm.HookKeyboard()

pythoncom.PumpMessages()
```
You will quickly see that, no matter what conventional python library you try, all of them will be flagged as injected. Thats because in the end, they all either rely on `SendInput` or `keyb_event` | `mouse_event`.

Why is this bad? Well, it's not always bad. If whatever you're sending inputs to currently works fine, and you are not worried about getting flagged by some sort of anti-cheat, then by all means its totally fine to stick to pyautogui / pydirectinput.

Alright, enough about that, onto the important shit.

## Why use this fork?
- Extremely simple interface, comparable to pyautogui / pydirectinput
- Dynamic keyboard adjustment for all kinds of layouts
- Refactored in a much more readable and documented fashion
- I work with loads of automation first hand so there is alot of QoL features.

## How to use?
First of all, you absolutely need to install the [interception-driver][c_ception], otherwise none of this will work. It's a very simple install.

Now, once you have all of that set up, you can go ahead and import `interception`.
The first thing you need to understand is that you have 10 different numbers for keyboard / mouse, and any of them could be the device you are
using. You can observe this by running the following program:
```py
import interception

interception.capture_keyboard()
interception.capture_mouse()
```
You can cancel the capture by pressing the ESC key, but every time you press a key or click with the mouse, you can see the intercepted event in the terminal.
The event consists of different kinds of flags and states, but also of the number of your device we just talked about.

To make sure that interception can actively send inputs from the correct devices, you have to set the correct devices. You can do this by manually checking the output,
but that gets pretty annoying as they can and will change sometimes. To make this easier, pyinterception has a method that will automatically capture a working device:
```py
import interception

interception.auto_capture_devices(keyboard=True, mouse=True)
```
So, now you can begin to send inputs, just like you are used to it from pyautogui or pydirectinput!
```py
interception.move_to(960, 540)

with interception.hold_key("shift"):
interception.press("a")

from interception import *

if __name__ == "__main__":
c = interception()
c.set_filter(interception.is_keyboard,interception_filter_key_state.INTERCEPTION_FILTER_KEY_UP.value)
while True:
device = c.wait()
stroke = c.receive(device)
if type(stroke) is key_stroke:
print(stroke.code)
c.send(device,stroke)
interception.click(120, 160, button="right", delay=1)
```

Have fun :D

[wrp]: https://github.com/cobrce/interception_wrapper
[wrp]: https://github.com/cobrce/interception_py
[c_ception]: https://github.com/oblitum/Interception
15 changes: 0 additions & 15 deletions _example_.py

This file was deleted.

17 changes: 0 additions & 17 deletions _example_hardwareid.py

This file was deleted.

Loading