Skip to content

Instantly share code, notes, and snippets.

@cobrce
Created April 3, 2021 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cobrce/4aa33b0ff7d13c81f1b55cc3347b9b62 to your computer and use it in GitHub Desktop.
Save cobrce/4aa33b0ff7d13c81f1b55cc3347b9b62 to your computer and use it in GitHub Desktop.
use interception_py to presse right button in the center of the screen
from interception import *
from win32api import GetSystemMetrics
# 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)
# 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_RIGHT_BUTTON_DOWN.value,
interception_mouse_flag.INTERCEPTION_MOUSE_MOVE_ABSOLUTE.value,
0,
int((0xFFFF * screen_width/2) / screen_width),
int((0xFFFF * screen_height/2) / 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_RIGHT_BUTTON_UP.value # update the stroke to release the button
context.send(mouse,mstroke) #button right is up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment