diff --git a/Interception.zip b/Interception.zip new file mode 100644 index 0000000..a9a90ab Binary files /dev/null and b/Interception.zip differ diff --git a/README.md b/README.md index 502616d..50c96f4 100644 --- a/README.md +++ b/README.md @@ -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 + ### why not using the wrapper? * it's very slow and some strokes are lost * fast strokes made python crash (some heap allocation errors) diff --git a/_example_.py b/_example_.py index ba7b3df..658b5a7 100644 --- a/_example_.py +++ b/_example_.py @@ -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) diff --git a/_get_keyboard.py b/_get_keyboard.py new file mode 100644 index 0000000..3ce5291 --- /dev/null +++ b/_get_keyboard.py @@ -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) + + # 最终发送成功的设备会输出其数值 \ No newline at end of file diff --git a/_get_mouse.py b/_get_mouse.py new file mode 100644 index 0000000..29d4b71 --- /dev/null +++ b/_get_mouse.py @@ -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) +# %% diff --git a/_left_click.py b/_left_click.py new file mode 100644 index 0000000..ffffcea --- /dev/null +++ b/_left_click.py @@ -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 +# %% diff --git a/_monitor_mouse.py b/_monitor_mouse.py new file mode 100644 index 0000000..6826add --- /dev/null +++ b/_monitor_mouse.py @@ -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) diff --git a/_mouse_scrolling.py b/_mouse_scrolling.py new file mode 100644 index 0000000..cb78a4a --- /dev/null +++ b/_mouse_scrolling.py @@ -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 +# %% diff --git a/_send_key.py b/_send_key.py new file mode 100644 index 0000000..3ce5291 --- /dev/null +++ b/_send_key.py @@ -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) + + # 最终发送成功的设备会输出其数值 \ No newline at end of file diff --git a/consts.py b/consts.py index 5ad70b8..8f6612f 100644 --- a/consts.py +++ b/consts.py @@ -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