我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用pyautogui.dragRel()。
def test_auto_gui(self): if self.cmd_switch: # Drag mouse to control some object on screen (such as google map at webpage) distance = 100. while distance > 0: pyautogui.dragRel(distance, 0, duration=2, button='left') # move right distance -= 25 pyautogui.dragRel(0, distance, duration=2, button='left') # move down distance -= 25 pyautogui.dragRel(-distance, 0, duration=2, button='left') # move right distance -= 25 pyautogui.dragRel(0, -distance, duration=2, button='left') # move down distance -= 25 # scroll mouse wheel (zoom in and zoom out google map) pyautogui.scroll(10, pause=1.) pyautogui.scroll(-10, pause=1) pyautogui.scroll(10, pause=1.) pyautogui.scroll(-10, pause=1) # message box pyautogui.alert(text='pyautogui testing over, click ok to end', title='Alert', button='OK') self.cmd_switch = not self.cmd_switch # turn off # main function of the project (run all processes)
def draw_rect(): time.sleep(5) distance = 200 while distance > 0: pyautogui.dragRel(distance, 0, duration=0.5) # move right distance -= 5 pyautogui.dragRel(0, distance, duration=0.5) # move down pyautogui.dragRel(-distance, 0, duration=0.5) # move left distance -= 5 pyautogui.dragRel(0, -distance, duration=0.5) # move up
def behaviour2() : pyautogui.click (500, 200) pyautogui.dragRel (100, 500, duration = 0.27) pyautogui.doubleclick() pyautogui.scroll (600) pyautogui.rightclick()
def input_control(self, count_defects, img_src): # update position difference with previous frame (for move mouse) d_x, d_y = 0, 0 if self.preCX is not None: d_x = self.ROIx - self.preCX d_y = self.ROIy - self.preCY # checking current command, and filter out unstable hand gesture cur_cmd = 0 if self.cmd_switch: if self.last_cmds.count(count_defects) >= self.last_cmds.n_maj: cur_cmd = count_defects #print 'major command is ', cur_cmd else: cur_cmd = 0 # self.last_cmds.major() else: cur_cmd = count_defects # send mouse input event depend on hand gesture if cur_cmd == 1: str1 = '2, move mouse dx,dy = ' + str(d_x*3) + ', ' + str(d_y*3) cv2.putText(img_src, str1, (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2) if self.cmd_switch: pyautogui.moveRel(d_x*3, d_y*3) self.last_cmds.push(count_defects) #pyautogui.mouseDown(button='left') #pyautogui.moveRel(d_x, d_y) #else: # pyautogui.mouseUp(button='left') elif cur_cmd == 2: cv2.putText(img_src, '3 Left (rotate)', (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2) if self.cmd_switch: pyautogui.dragRel(d_x, d_y, button='left') self.last_cmds.push(count_defects) #pyautogui.scroll(d_y,pause=0.2) elif cur_cmd == 3: cv2.putText(img_src, '4 middle (zoom)', (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2) if self.cmd_switch: pyautogui.dragRel(d_x, d_y, button='middle') self.last_cmds.push(count_defects) elif cur_cmd == 4: cv2.putText(img_src, '5 right (pan)', (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2) if self.cmd_switch: pyautogui.dragRel(d_x, d_y, button='right') self.last_cmds.push(count_defects) elif cur_cmd == 5: cv2.putText(img_src, '1 fingertip show up', (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2) if self.cmd_switch: self.last_cmds.push(count_defects) else: cv2.putText(img_src, 'No finger detect!', (50, 50), cv2.FONT_HERSHEY_TRIPLEX, 2, (0, 0, 255), 2) if self.cmd_switch: self.last_cmds.push(count_defects) # no finger detect or wrong gesture # testing pyautogui