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

左键点击interception #6

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added Interception.zip
Binary file not shown.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# interception_py
This is a port (not a [wrapper][wrp]) of [interception][c_ception] dll to python, it communicates directly with interception's driver

### 安装驱动
Interception.zip
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A personal preference here : I prefer not including binary files, but rather a link to their original repositories


### why not using the wrapper?
* it's very slow and some strokes are lost
* fast strokes made python crash (some heap allocation errors)
Expand Down
1 change: 1 addition & 0 deletions _example_.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
c.set_filter(interception.is_keyboard,interception_filter_key_state.INTERCEPTION_FILTER_KEY_UP.value)
while True:
device = c.wait()
print('Device: %d' % device)
stroke = c.receive(device)
if type(stroke) is key_stroke:
print(stroke.code)
Expand Down
36 changes: 36 additions & 0 deletions _get_keyboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 检查哪个键盘可以用
from interception import *
from consts import *
from stroke import *
import time

class ScanCode():
ESC = 1
NUM1 = 2
NUM2 = 3
NUM3 = 4
NUM4 = 5
NUM5 = 6
NUM6 = 7
NUM7 = 8
NUM8 = 9
NUM9 = 10
NUM0 = 11
M = 50
MINUS = 12

KEY_DOWN = 0
KEY_UP = 1

def send_key(device:int, scancode:int):
c = interception()
c.send(device, key_stroke(scancode,ScanCode.KEY_DOWN,0))
c.send(device, key_stroke(scancode,ScanCode.KEY_UP,0))

if __name__ == "__main__":
# time.sleep(5)
for device in range(MAX_KEYBOARD):
numkey = eval('ScanCode.NUM' + str(device))
send_key(device, numkey)

# 最终发送成功的设备会输出其数值
43 changes: 43 additions & 0 deletions _get_mouse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#%%
import time
from interception import *
from win32api import GetSystemMetrics

#%%
# 需要点击的坐标
x, y = 320, 200
screen_width = GetSystemMetrics(0)
screen_height = GetSystemMetrics(1)

# create a context for interception to use to send strokes, in this case
# we won't use filters, we will manually search for the first found mouse
context = interception()

# loop through all devices and check if they correspond to a mouse
mouseList = []
for mouse in range(MAX_DEVICES):
if interception.is_mouse(mouse):
mouseList.append(mouse)

# no mouse we quit
if (len(mouseList) == 0):
print("No mouse found")
exit(0)

# 通过点击检查哪些鼠标可以用
for mouse in mouseList:
print("Mouse: %d" % mouse)

mstroke = mouse_stroke(interception_mouse_state.INTERCEPTION_MOUSE_LEFT_BUTTON_DOWN.value,
interception_mouse_flag.INTERCEPTION_MOUSE_MOVE_ABSOLUTE.value,
0,
int((0xFFFF * x) / screen_width),
int((0xFFFF * y) / screen_height),
0)

context.send(mouse,mstroke)

mstroke.state = interception_mouse_state.INTERCEPTION_MOUSE_LEFT_BUTTON_UP.value
context.send(mouse,mstroke)
time.sleep(2)
# %%
46 changes: 46 additions & 0 deletions _left_click.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#%%
from interception import *
from win32api import GetSystemMetrics
#%%
# 需要点击的坐标
# x,y = 553,337
x,y = 23,303
# x,y = 554,82
# get screen size
screen_width = GetSystemMetrics(0)
screen_height = GetSystemMetrics(1)

# create a context for interception to use to send strokes, in this case
# we won't use filters, we will manually search for the first found mouse
context = interception()

# loop through all devices and check if they correspond to a mouse
mouse = 0
for i in range(MAX_DEVICES):
if interception.is_mouse(i):
mouse = i
break

# no mouse we quit
if (mouse == 0):
print("No mouse found")
exit(0)

# 鼠标14可以用
mouse = 11

# we create a new mouse stroke, initially we use set right button down, we also use absolute move,
# and for the coordinate (x and y) we use center screen
mstroke = mouse_stroke(interception_mouse_state.INTERCEPTION_MOUSE_LEFT_BUTTON_DOWN.value,
interception_mouse_flag.INTERCEPTION_MOUSE_MOVE_ABSOLUTE.value,
0,
int((0xFFFF * x) / screen_width),
int((0xFFFF * y) / screen_height),
0)

context.send(mouse,mstroke) # we send the key stroke, now the right button is down

mstroke.state = interception_mouse_state.INTERCEPTION_MOUSE_LEFT_BUTTON_UP.value # update the stroke to release the button
# mstroke.state = interception_mouse_state.INTERCEPTION_MOUSE_RIGHT_BUTTON_UP.value # update the stroke to release the button
context.send(mouse,mstroke) #button right is up
# %%
16 changes: 16 additions & 0 deletions _monitor_mouse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from interception import *
from consts import *

if __name__ == "__main__":
c = interception()
c.set_filter(interception.is_mouse,interception_filter_mouse_state.INTERCEPTION_FILTER_MOUSE_ALL.value)
# c.set_filter(interception.is_mouse,interception_filter_mouse_state.INTERCEPTION_FILTER_MOUSE_WHEEL.value)
while True:
device = c.wait()
print('Device: %d' % device)
stroke = c.receive(device)
if type(stroke) is mouse_stroke:
print("state: %d,\tflags: %d,\trolling: %d,\tx: %d,\ty: %d,\tinfo:%d" % (stroke.state, stroke.flags, stroke.rolling, stroke.x, stroke.y, stroke.information))
c.send(device,stroke)
# hwid = c.get_HWID(device)
# print(u"%s" % hwid)
25 changes: 25 additions & 0 deletions _mouse_scrolling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from interception import *
from win32api import GetSystemMetrics

mouse = 13
x,y = 100, 290

screen_width = GetSystemMetrics(0)
screen_height = GetSystemMetrics(1)
xT = int((0xFFFF * x) / screen_width)
yT = int((0xFFFF * y) / screen_height)

context = interception()
mstroke = mouse_stroke(interception_mouse_state.INTERCEPTION_MOUSE_WHEEL.value,
interception_mouse_flag.INTERCEPTION_MOUSE_MOVE_ABSOLUTE.value,
120,
xT,
yT,
0)

context.send(mouse,mstroke) # we send the key stroke, now the right button is down

# mstroke.state = interception_mouse_state.INTERCEPTION_MOUSE_LEFT_BUTTON_UP.value # update the stroke to release the button
# mstroke.state = interception_mouse_state.INTERCEPTION_MOUSE_RIGHT_BUTTON_UP.value # update the stroke to release the button
# context.send(mouse,mstroke) #button right is up
# %%
36 changes: 36 additions & 0 deletions _send_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 检查哪个键盘可以用
from interception import *
from consts import *
from stroke import *
import time

class ScanCode():
ESC = 1
NUM1 = 2
NUM2 = 3
NUM3 = 4
NUM4 = 5
NUM5 = 6
NUM6 = 7
NUM7 = 8
NUM8 = 9
NUM9 = 10
NUM0 = 11
M = 50
MINUS = 12

KEY_DOWN = 0
KEY_UP = 1

def send_key(device:int, scancode:int):
c = interception()
c.send(device, key_stroke(scancode,ScanCode.KEY_DOWN,0))
c.send(device, key_stroke(scancode,ScanCode.KEY_UP,0))

if __name__ == "__main__":
# time.sleep(5)
for device in range(MAX_KEYBOARD):
numkey = eval('ScanCode.NUM' + str(device))
send_key(device, numkey)

# 最终发送成功的设备会输出其数值
2 changes: 2 additions & 0 deletions consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class interception_mouse_state (Enum):

INTERCEPTION_MOUSE_WHEEL = 0x400
INTERCEPTION_MOUSE_HWHEEL = 0x800

INTERCEPTION_MOUSE_MOVE = 0x1000

class interception_filter_mouse_state(Enum):
INTERCEPTION_FILTER_MOUSE_NONE = 0x0000
Expand Down