-
Notifications
You must be signed in to change notification settings - Fork 13
左键点击interception #6
base: master
Are you sure you want to change the base?
Changes from 6 commits
1025166
0c4f2a6
51dc569
b54ee42
dee3f52
98c7746
1ea33ca
3bbd46f
a2c9318
bcd4b4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # 此脚本返回 0 - 9 的所有数值, 似乎无法正确判断keyboard | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comments in English are more appreciated, it's not my native language neither but it's widely understood
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right |
||
|
|
||
| from interception import * | ||
|
|
||
| context = interception() | ||
|
|
||
| for i in range(10): | ||
| if interception.is_keyboard(i): | ||
| print('keyboard:',i) | ||
| 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 = 513,110 | ||
| # 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 = 14 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code from line 25 to 27 exits if there is no mouse, why did you arbitrarily pick 14?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, 14 only works on my computer. |
||
|
|
||
| # 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 | ||
| # %% | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from interception import * | ||
| from consts import * | ||
| from stroke import * | ||
| import time | ||
|
|
||
| class ScanCode(): | ||
| ESC = 1 | ||
| 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__": | ||
| device = 8 # 0-10, 根据机器情况修改 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, an example should be more generic, I guess that 8 corresponds to your keyboard, but it's not the case in every machine, using a loop to search for keyboards or simply get it as input seems more appropriate
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, I do use loop detection in use, but I haven't updated the code yet |
||
| time.sleep(5) | ||
| send_key(device, ScanCode.ESC) | ||
There was a problem hiding this comment.
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