Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
keyboard.add_hotkey('Ctrl + 2', lambda: pyautogui.mouseUp() or winsound.Beep(1000, duration=50))
def click_up(self, button=MouseButton.LEFT, **kwargs):
if ("force" in kwargs and kwargs["force"] is True) or self.game_is_focused:
pyautogui.mouseUp(button=mouse_button_mapping[button.name])
def mouse_up(self, button='left'):
'''Releases specified mouse button'''
ag.mouseUp(button=button)
while True:
_, img = cam.read()
img = cv2.flip(img, 1)
imgHSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(imgHSV, lower, upper)
blur = cv2.medianBlur(mask, 15)
blur = cv2.GaussianBlur(blur , (5,5), 0)
thresh = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]
contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[1]
mposx, mposy = gui.position()
#print(flags)
if len(contours) >= 2:
old_center[0] = center[0]
if is_mouse_down:
Thread(target=gui.mouseUp, args=()).start()
is_mouse_down = False
# if left click was done
if flags[1] == True:
is_mouse_down = False
# do a right click if the fingers were together for 10-20 frames and then released
if finger_frame_count[1] >= 10 and finger_frame_count[1] <= 20:
gui.rightClick()
# else if fingers were together for less than 10 frames then do a left click
elif finger_frame_count[1] < 10:
gui.click()
finger_frame_count[1] = 0
finger_frame_count[2] += 1
c1, c2 = top(contours, cv2.contourArea, 2)
def drag_mouse( self, should_drag ):
if( self.should_drag != should_drag ):
if( should_drag == True ):
print( "Start dragging!" )
mouseDown()
else:
print( "Stopped dragging!" )
mouseUp()
self.should_drag = should_drag
# do a left click and hold if the fingers were together for more than 20 frames
if finger_frame_count[1] > 20:
if not is_mouse_down:
gui.mouseDown()
is_mouse_down = True
if np.any(abs(center[1] - old_center[1]) > 5):
Thread(target=gui.moveTo, args=(mposx+(center[1][0]-old_center[1][0])*sx, mposy + (center[1][1]-old_center[1][1])*sy, \
0.1, gui.easeInOutQuad)).start()
flags = [False, True, False]
else:
flags = [True, False, False]
else:
if is_mouse_down:
Thread(target=gui.mouseUp, args=()).start()
thread.start_new_thread(gui.mouseUp, ())
is_mouse_down = False
flags = [True, False, False]
cv2.imshow("Virtual Mouse", img)
if cv2.waitKey(1) == ord('q'):
break
cam.release()
cv2.destroyAllWindows()
gui.mouseUp()
if t.data == "delay":
sec = do(t.children[0])
pyautogui.PAUSE = sec
return
if t.data == "drag":
btn = do(t.children[0])
cs = []
for c in t.children[1:]:
cs.append(do(c))
# pyautogui.drag(*cs, button=btn)
# hack, because the cursor keeps moving...?
pyautogui.mouseDown(button=btn)
pyautogui.moveTo(cs[0], cs[1])
pyautogui.mouseUp(button=btn)
return
if t.data == "coord":
name = do(t.children[0])
t = do(t.children[1])
pnt = coords[name][screen]
x, y = pnt[0], pnt[1]
pyautogui.moveTo(x, y, t, pyautogui.easeOutQuad)
return
if t.data == "coord_off":
name = do(t.children[0])
x = do(t.children[1])
y = do(t.children[2])
def mouseUpAction( self, button='left' ):
print( "----------> RELEASING MOUSE " + button )
pyautogui.mouseUp( button=button )