我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用pyautogui.scroll()。
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 chooseAction(yp, rc, bc): out = np.array(['move', 'false']) if rc[0]!=-1 and bc[0]!=-1: if distance(yp,rc)<50 and distance(yp,bc)<50 and distance(rc,bc)<50 : out[0] = 'drag' out[1] = 'true' return out elif distance(rc,bc)<40: out[0] = 'left' return out elif distance(yp,rc)<40: out[0] = 'right' return out elif distance(yp,rc)>40 and rc[1]-bc[1]>120: out[0] = 'down' return out elif bc[1]-rc[1]>110: out[0] = 'up' return out else: return out else: out[0] = -1 return out # Movement of cursor on screen, left click, right click,scroll up, scroll down # and dragging actions are performed here based on value stored in 'action'.
def chooseAction(yp, rc, bc, actionHistory): out = np.array(['move', 'false']) if rc[0]!=-1 and bc[0]!=-1: if not leftHand and checkActionHistory( actionHistory, 'ONOFF'): if bc[0]-yp[0]>130 and bc[1]-yp[1]>170 and bc[1]-rc[1]<40: out[0] = 'ONOFF' return out elif leftHand and checkActionHistory( actionHistory, 'ONOFF'): if yp[0]-bc[0]>130 and bc[1]-yp[1]>170 and bc[1]-rc[1]<40: out[0] = 'ONOFF' return out if distance(yp,rc)<50 and distance(yp,bc)<50 and distance(rc,bc)<50 : out[0] = 'drag' out[1] = 'true' return out elif distance(rc,bc)<40: out[0] = 'left' return out elif distance(yp,rc)<40 and checkActionHistory( actionHistory, 'right'): out[0] = 'right' return out elif distance(yp,rc)>40 and rc[1]-bc[1]>120: out[0] = 'down' return out elif bc[1]-rc[1]>110: out[0] = 'up' return out else: return out else: out[0] = -1 return out # Movement of cursor on screen, left click, right click,scroll up, scroll down # and dragging actions are performed here based on value stored in 'action'.
def behaviour2() : pyautogui.click (500, 200) pyautogui.dragRel (100, 500, duration = 0.27) pyautogui.doubleclick() pyautogui.scroll (600) pyautogui.rightclick()
def handle_mouse_scroll_down_intent(self, message): self.speak('scrolling down now') scroll = message.data.get('Scroll') scroll_down = int(scroll) * -1 pyautogui.scroll(scroll_down)
def handle_mouse_scroll_up_intent(self, message): self.speak('scrolling up now') scroll = message.data.get('Scroll') scroll_up = int(scroll) pyautogui.scroll(scroll_up)
def handle_mouse_scroll_right_intent(self, message): if platform.system().lower().startswith('lin'): self.speak('scrolling right now') scroll = message.data.get('Scroll') scroll_right = int(scroll) pyautogui.hscroll(scroll_right) else: self.speak('Sorry, I cannot scroll right on your current operating system')
def scroll_down(self): pyautogui.scroll(200) # Scrolls the pyautogui print("SCROLLING") time.sleep(1)
def scroll_up(self): pyautogui.scroll(-90) # time.sleep(1)
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