Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_itemscanvas_select(self):
canvas = ItemsCanvas()
canvas.pack()
canvas.add_item("item", font=("default", 16))
self.window.wm_geometry("+0+0")
self.window.update()
mouse_controller = Controller()
mouse_controller.position = (30, 40)
self.window.update()
mouse_controller.press(Button.left)
self.window.update()
mouse_controller.release(Button.left)
self.window.update()
def swipe(self, p1, p2, duration=0.5, steps=5, fingers=1, button='left'):
if button is "middle":
button = Button.middle
elif button is "right":
button = Button.right
elif button is "left":
button = Button.left
else:
raise ValueError("Unknow button: " + button)
x1, y1 = p1
x2, y2 = p2
x1 = x1 + self.monitor["left"]
x2 = x2 + self.monitor["left"]
y1 = y1 + self.monitor["top"]
y2 = y2 + self.monitor["top"]
ratio_x = self.monitor["width"] / self.singlemonitor["width"]
ratio_y = self.monitor["height"] / self.singlemonitor["height"]
x2 = x1 + (x2 - x1) / ratio_x
y2 = y1 + (y2 - y1) / ratio_y
m = Controller()
interval = float(duration) / (steps + 1)
m.position = (x1, y1)
m.press(button)
def swipe(self, p1, p2, duration=0.5, steps=5, fingers=1, button='left'):
set_foreground_window(self.window)
if button is "middle":
button = Button.middle
elif button is "right":
button = Button.right
elif button is "left":
button = Button.left
else:
raise ValueError("Unknow button: " + button)
x1, y1 = p1
x2, y2 = p2
# 设置坐标时相对于整个屏幕的坐标:
x1 = x1 + self.monitor["left"]
x2 = x2 + self.monitor["left"]
y1 = y1 + self.monitor["top"]
y2 = y2 + self.monitor["top"]
# 双屏时,涉及到了移动的比例换算:
if len(self.screen.monitors) > 2:
ratio_x = (
self.monitor["width"] + self.monitor["left"]) / self.singlemonitor["width"]
ratio_y = (
self.monitor["height"] + self.monitor["top"]) / self.singlemonitor["height"]
lastYPos = evDevValue # X is Y
elif evDevCode == WACOM_EVCODE_YPOS:
lastXPos = evDevValue # Y is X
elif evDevCode == WACOM_EVCODE_XTILT:
lastXTilt = evDevValue
elif evDevCode == WACOM_EVCODE_YTILT:
lastYTilt = evDevValue
elif evDevCode == WACOM_EVCODE_DISTANCE:
lastDistance = evDevValue
elif evDevCode == WACOM_EVCODE_PRESSURE:
if not ONLY_DEBUG:
if not mouseButtonPressed and evDevValue > SCREEN_DRAW_BUTTON_PRESSURE:
mouse.press(Button.left)
mouseButtonPressed = True
elif mouseButtonPressed and evDevValue <= SCREEN_DRAW_BUTTON_PRESSURE:
mouse.release(Button.left)
mouseButtonPressed = False
lastPressure = evDevValue
if ONLY_DEBUG:
print('XPos: %5d | YPos: %5d | XTilt: %5d | YTilt: %5d | Distance: %3d | Pressure: %4d' % (lastXPos, lastYPos, lastXTilt, lastYTilt, lastDistance, lastPressure))
else:
screenX = SCREEN_DRAW_AREA_FROM_X + round(lastXPos * ratioX) # (X doesn't need to invert)
screenY = SCREEN_DRAW_AREA_FROM_Y + round((WACOM_HEIGHT - lastYPos) * ratioY) # (Y has to be inverted)
mouseMoveAbs(screenX, screenY)
print('---------------------')
mouse_listener = mouse.Listener(
on_move=on_move,
on_scroll=on_scroll,
on_click=on_click
)
mouse_listener.start()
time.sleep(1)
# ============ mouse control ============
mouse_ctl = mouse.Controller()
mouse_ctl.position = (100, 200)
mouse_ctl.press(Button.left)
mouse_ctl.position = (100, 150)
mouse_ctl.release(Button.left)
# mouse_ctl.scroll(0, 2)
time.sleep(1)
# ============ keyboard hook ============
def on_press(key):
print('---- keyboard hook -----')
if isinstance(key, Key):
print('Key:', key.name, key.value.vk)
elif isinstance(key, KeyCode):
print('KeyCode:', key.char, key.vk)
else:
def bounce():
mouse.position = (180, 350)
mouse.click(Button.left, 1)
mouse.position = startPos #Set mouse position
while grayThresh < 255:
print("GrayThresh :", grayThresh) #Prints the current max rgb value
print((grayThresh / 255) * 100, "%") #Prints the percentage (%)
for i in range(len(img)): #For each row:
mouse.position = (startPos[0], mouse.position[1])
mouse.move(0, 1)
for j in range(len(img[i])): #For each column:
if grayThresh - threshStep < img[i, j, 0] <= grayThresh: #If pixel(i(x), j(y)) has color darker than
#the current max rgb value (grayThresh) and brighter
#than the grayThresh before:
mouse.click(Button.left, 1) #Click (paint)
time.sleep(0.0005) #Some delay (This is needed for ms paint to properly register the clicks)
mouse.move(1, 0) #Move mouse cursor to the next pixel
#print(mouse.position)
grayThresh += threshStep #After it scanned through the whole image, increase max rgb value (grayThresh)
#by threshStep
print("GrayThresh :", grayThresh)
# <>
# All delays (time.sleep) are needed for ms paint to register the mouse / keyboard actions
# They can be shortened
mouse.position = (1030, 80) #SELECT COLOR Button pixel coordinates
mouse.click(Button.left, 1)
X = int(float(x.text))
y = sauce.find('accelerometer2')
Y = int(float(y.text))
#z = sauce.find('accelerometer3')
#Z = int(float(z.text))
#print(X)
#print(Y)
#Pythagoras Theorem for 3rd axis
#h1 = int(math.sqrt(X**2 + Z**2))
#h2 = int(math.sqrt(Y**2 + Z**2))
single_click = sauce.find('lightintensity')
mouse.move(-X*4,-Y*4)
#left click
if int(float(single_click.text)) <= 10:
mouse.click(Button.left)
mouse.release(Button.left)
#print("Right Click")
n = (b/740)*100
k = (width*m)/100
c = (height*n)/100
#pyautogui.FAILSAFE = False
#pyautogui.moveTo(k,c)
if check == True :
#print('h')
#mouse.position = (int(k), int(c))
mouse.press(Button.left)
mouse.release(Button.left)
else:
mouse.release(Button.left)
check = False
cv2.imshow('frame',frame)
cv2.imshow('dilate',otsu)
k=cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
cap.release()
width, height = pyautogui.size()
m = (a/1280)*100
n = (b/740)*100
k = (width*m)/100
c = (height*n)/100
#pyautogui.FAILSAFE = False
#pyautogui.moveTo(k,c)
if check == True :
#print('h')
#mouse.position = (int(k), int(c))
mouse.press(Button.left)
mouse.release(Button.left)
else:
mouse.release(Button.left)
check = False
cv2.imshow('frame',frame)
cv2.imshow('dilate',otsu)
k=cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()