Python pyautogui.moveTo() Examples
The following are 23
code examples of pyautogui.moveTo().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyautogui
, or try the search function
.
Example #1
Source File: test_pyautogui.py From pyautogui with BSD 3-Clause "New" or "Revised" License | 7 votes |
def test_failsafe(self): self.oldFailsafeSetting = pyautogui.FAILSAFE pyautogui.moveTo(1, 1) # make sure mouse is not in failsafe position to begin with for x, y in pyautogui.FAILSAFE_POINTS: pyautogui.FAILSAFE = True # When move(), moveTo(), drag(), or dragTo() moves the mouse to a # failsafe point, it shouldn't raise the fail safe. (This would # be annoying. Only a human moving the mouse to a failsafe point # should trigger the failsafe.) pyautogui.moveTo(x, y) pyautogui.FAILSAFE = False pyautogui.moveTo(1, 1) # make sure mouse is not in failsafe position to begin with (for the next iteration) pyautogui.moveTo(1, 1) # make sure mouse is not in failsafe position to begin with for x, y in pyautogui.FAILSAFE_POINTS: pyautogui.FAILSAFE = True pyautogui.moveTo(x, y) # This line should not cause the fail safe exception to be raised. # A second pyautogui function call to do something while the cursor is in a fail safe point SHOULD raise the failsafe: self.assertRaises(pyautogui.FailSafeException, pyautogui.press, "esc") pyautogui.FAILSAFE = False pyautogui.moveTo(1, 1) # make sure mouse is not in failsafe position to begin with (for the next iteration) for x, y in pyautogui.FAILSAFE_POINTS: pyautogui.FAILSAFE = False pyautogui.moveTo(x, y) # This line should not cause the fail safe exception to be raised. # This line shouldn't cause a failsafe to trigger because FAILSAFE is set to False. pyautogui.press("esc") pyautogui.FAILSAFE = self.oldFailsafeSetting
Example #2
Source File: recovery.py From kcauto with GNU General Public License v3.0 | 6 votes |
def basic_recovery(): """Method that contains steps for basic recovery attempt, which involves clearing any interaction-blocking browser popups. Returns: bool: True if recovery was successful; False otherwise. """ Log.log_debug("Attempting Basic Recovery.") if cfg.config.general.is_direct_control: pyautogui.moveTo(1, 1) pyautogui.press('esc') sleep(0.5) pyautogui.press('space') sleep(0.5) pyautogui.press('f10') sleep(0.5) try: if kca_u.kca.find_kancolle(): return True except FindFailed: pass return False
Example #3
Source File: test_pyautogui.py From pyautogui with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_moveRelWithTween(self): origin = self.center - P(100, 100) delta = P(200, 200) destination = origin + delta def resetMouse(): pyautogui.moveTo(*origin) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, origin) for tweenName in self.TWEENS: tweenFunc = getattr(pyautogui, tweenName) resetMouse() pyautogui.moveRel(delta.x, delta.y, duration=pyautogui.MINIMUM_DURATION * 2, tween=tweenFunc) mousepos = P(*pyautogui.position()) self.assertEqual( mousepos, destination, "%s tween move failed. mousepos set to %s instead of %s" % (tweenName, mousepos, destination), )
Example #4
Source File: ImageCoordinate.py From roc with MIT License | 5 votes |
def coords(this, shot=True): this = this + '.png' if shot: Screenshot.shot() else: print('No screenshot') small_image = cv2.imread(this) h, w, c = small_image.shape large_image = cv2.imread('playing.png') result = cv2.matchTemplate( small_image, large_image, cv2.TM_SQDIFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) # print('ImageCoordinate::coords => ' + this + ' ' + str(min_val)) mn, _, mn_loc, mx_loc = cv2.minMaxLoc(result) mp_x, mp_y = mn_loc # #pyautogui.moveTo(mp_x, mp_y) # top_left = mn_loc # mx_right = mx_loc # bt_rt =(top_left[0]+h,top_left[1]+w) # cv2.rectangle(large_image,top_left,bt_rt,255,2) # bt_rt =(mx_right[0]+h,mx_right[1]+w) # cv2.rectangle(large_image,mx_right,bt_rt,255,2) # cv2.imwrite('result_'+this.replace('images/',''), large_image) # print('saved'+str(min_val)) if min_val > 0.2: return [0, 0, min_val] mn, _, mn_loc, _ = cv2.minMaxLoc(result) mp_x, mp_y = mn_loc ordinal = random.randrange(1, 15) a = random.randrange(-ordinal, ordinal) b = random.randrange(-ordinal, ordinal) location = [mp_x + w / 2+a, mp_y + h / 2+b, min_val] return location
Example #5
Source File: lianliankan.py From lianliankan with MIT License | 5 votes |
def execute_one_step(one_step): from_row, from_col, to_row, to_col = one_step from_x = game_area_left + (from_col + 0.5) * grid_width from_y = game_area_top + (from_row + 0.5) * grid_height to_x = game_area_left + (to_col + 0.5) * grid_width to_y = game_area_top + (to_row + 0.5) * grid_height pyautogui.moveTo(from_x, from_y) pyautogui.click() pyautogui.moveTo(to_x, to_y) pyautogui.click()
Example #6
Source File: hearthstone_auto.py From hearthstone_script- with MIT License | 5 votes |
def atack(fromx, fromy): mouse_click(fromx, fromy) pymouse.moveTo(960, 800, duration=0.3) enemy_sneer = detect_sneer() if len(enemy_sneer): # 检测到嘲讽怪 mouse_click(490 + enemy_sneer[0], 360) time.sleep(1) else: mouse_click(960, 210) time.sleep(1)
Example #7
Source File: hearthstone_auto.py From hearthstone_script- with MIT License | 5 votes |
def mouse_drag_from_to(fromx, fromy, tox, toy): pymouse.moveTo(fromx, fromy) pymouse.dragTo(tox, toy, duration=0.3)
Example #8
Source File: autoplay.py From AIGames with MIT License | 5 votes |
def click(self, position): # pyautogui.moveTo(position[0], position[1], duration=1) pyautogui.click(position[0], position[1]) # 截屏
Example #9
Source File: humanclicker.py From pyclick with MIT License | 5 votes |
def move(self, toPoint, duration=2, humanCurve=None): fromPoint = pyautogui.position() if not humanCurve: humanCurve = HumanCurve(fromPoint, toPoint) pyautogui.PAUSE = duration / len(humanCurve.points) for point in humanCurve.points: pyautogui.moveTo(point)
Example #10
Source File: YuHunModule.py From yysScript with Apache License 2.0 | 5 votes |
def Click(targetPosition): """ 点击屏幕上的某个点 :param targetPosition: :return: """ if targetPosition is None: print('未检测到目标') else: pyautogui.moveTo(targetPosition, duration=0.20) pyautogui.click() time.sleep(random.randint(500, 1000) / 1000) # time.sleep(random.randint(100, 150) / 1000)
Example #11
Source File: tools.py From Dindo-Bot with MIT License | 5 votes |
def move_mouse_to(position): pyautogui.moveTo(position)
Example #12
Source File: tools.py From Dindo-Bot with MIT License | 5 votes |
def perform_click(x, y, double=False): old_position = pyautogui.position() if double: pyautogui.doubleClick(x=x, y=y, interval=0.1) else: pyautogui.click(x=x, y=y) pyautogui.moveTo(old_position) # Press key
Example #13
Source File: _mouse.py From robotframework-imagehorizonlibrary with MIT License | 5 votes |
def move_to(self, *coordinates): '''Moves the mouse pointer to an absolute coordinates. ``coordinates`` can either be a Python sequence type with two values (eg. ``(x, y)``) or separate values ``x`` and ``y``: | Move To | 25 | 150 | | | @{coordinates}= | Create List | 25 | 150 | | Move To | ${coordinates} | | | | ${coords}= | Evaluate | (25, 150) | | | Move To | ${coords} | | | X grows from left to right and Y grows from top to bottom, which means that top left corner of the screen is (0, 0) ''' if len(coordinates) > 2 or (len(coordinates) == 1 and type(coordinates[0]) not in (list, tuple)): raise MouseException('Invalid number of coordinates. Please give ' 'either (x, y) or x, y.') if len(coordinates) == 2: coordinates = (coordinates[0], coordinates[1]) else: coordinates = coordinates[0] try: coordinates = [int(coord) for coord in coordinates] except ValueError: raise MouseException('Coordinates %s are not integers' % (coordinates,)) ag.moveTo(*coordinates)
Example #14
Source File: test_pyautogui.py From pyautogui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): self.oldFailsafeSetting = pyautogui.FAILSAFE pyautogui.FAILSAFE = False pyautogui.moveTo(42, 42) # make sure failsafe isn't triggered during this test pyautogui.FAILSAFE = True
Example #15
Source File: ImageCoordinate.py From roc with MIT License | 5 votes |
def is_on_screen(this, accuracy=0.14): this = this + '.png' Screenshot.shot() small_image = cv2.imread(this) h, w, c = small_image.shape large_image = cv2.imread('playing.png') result = cv2.matchTemplate( small_image, large_image, cv2.TM_SQDIFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) #print('ImageCoordinate::is_on_screen => ' + this + ' ' + str(min_val)) mn, _, mn_loc, mx_loc = cv2.minMaxLoc(result) mp_x, mp_y = mn_loc m_x, m_y = mx_loc # print(mn_loc) # top_left = mn_loc # mx_right = mx_loc bt_rt = (mn_loc[0], mn_loc[1]) bt_rtw = (mn_loc[0]+w, mn_loc[1]+h) # cv2.rectangle(large_image,top_left,bt_rt,255,2) # bt_rt =(mx_right[0]+h,mx_right[1]+w) # cv2.rectangle(large_image,mx_right,bt_rt,255,2) # cv2.imwrite('result_'+this.replace('images/',''), large_image) # print('saved') #pyautogui.moveTo(mp_x, mp_y) print(min_val) if min_val > accuracy: return False else: mn, _, mn_loc, _ = cv2.minMaxLoc(result) mp_x, mp_y = mn_loc ordinal = random.randrange(1, 15) a = random.randrange(-ordinal, ordinal) b = random.randrange(-ordinal, ordinal) location = [mp_x + w / 2+a, mp_y + h / 2+b, bt_rt, bt_rtw, min_val] return location
Example #16
Source File: imagesearch.py From python-imagesearch with MIT License | 5 votes |
def click_image(image, pos, action, timestamp, offset=5): img = cv2.imread(image) height, width, channels = img.shape pyautogui.moveTo(pos[0] + r(width / 2, offset), pos[1] + r(height / 2, offset), timestamp) pyautogui.click(button=action)
Example #17
Source File: test_pyautogui.py From pyautogui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): self.oldFailsafeSetting = pyautogui.FAILSAFE pyautogui.FAILSAFE = False pyautogui.moveTo(42, 42) # make sure failsafe isn't triggered during this test pyautogui.FAILSAFE = True
Example #18
Source File: test_pyautogui.py From pyautogui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_moveTo(self): # moving the mouse desired = self.center pyautogui.moveTo(*desired) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # no coordinate specified (should be a NO-OP) pyautogui.moveTo(None, None) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # moving the mouse to a new location desired += P(42, 42) pyautogui.moveTo(*desired) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # moving the mouse over time (1/5 second) desired -= P(42, 42) pyautogui.moveTo(desired.x, desired.y, duration=0.2) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a list instead of separate x and y. desired += P(42, 42) pyautogui.moveTo(list(desired)) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a tuple instead of separate x and y. desired += P(42, 42) pyautogui.moveTo(tuple(desired)) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a sequence-like object instead of separate x and y. desired -= P(42, 42) pyautogui.moveTo(desired) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired)
Example #19
Source File: test_pyautogui.py From pyautogui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): self.oldFailsafeSetting = pyautogui.FAILSAFE self.center = P(*pyautogui.size()) // 2 pyautogui.FAILSAFE = False pyautogui.moveTo(*self.center) # make sure failsafe isn't triggered during this test pyautogui.FAILSAFE = True
Example #20
Source File: test_pyautogui.py From pyautogui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_pause(self): oldValue = pyautogui.PAUSE startTime = time.time() pyautogui.PAUSE = 0.35 # there should be a 0.35 second pause after each call pyautogui.moveTo(1, 1) pyautogui.moveRel(0, 1) pyautogui.moveTo(1, 1) elapsed = time.time() - startTime self.assertTrue(1.0 < elapsed < 1.1, "Took %s seconds, expected 1.0 < 1.1 seconds." % (elapsed)) pyautogui.PAUSE = oldValue # restore the old PAUSE value
Example #21
Source File: test_pyautogui.py From pyautogui with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_position(self): mousex, mousey = pyautogui.position() self.assertTrue(isinstance(mousex, int), "Type of mousex is %s" % (type(mousex))) self.assertTrue(isinstance(mousey, int), "Type of mousey is %s" % (type(mousey))) # Test passing x and y arguments to position(). pyautogui.moveTo(mousex + 1, mousey + 1) x, y = pyautogui.position(mousex, None) self.assertEqual(x, mousex) self.assertNotEqual(y, mousey) x, y = pyautogui.position(None, mousey) self.assertNotEqual(x, mousex) self.assertEqual(y, mousey)
Example #22
Source File: test_pyautogui.py From pyautogui with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_moveRel(self): # start at the center desired = self.center pyautogui.moveTo(*desired) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move down and right desired += P(42, 42) pyautogui.moveRel(42, 42) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move up and left desired -= P(42, 42) pyautogui.moveRel(-42, -42) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move right desired += P(42, 0) pyautogui.moveRel(42, 0) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move down desired += P(0, 42) pyautogui.moveRel(0, 42) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move left desired += P(-42, 0) pyautogui.moveRel(-42, 0) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # move up desired += P(0, -42) pyautogui.moveRel(0, -42) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a list instead of separate x and y. desired += P(42, 42) pyautogui.moveRel([42, 42]) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a tuple instead of separate x and y. desired -= P(42, 42) pyautogui.moveRel((-42, -42)) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired) # Passing a sequence-like object instead of separate x and y. desired += P(42, 42) pyautogui.moveRel(P(42, 42)) mousepos = P(*pyautogui.position()) self.assertEqual(mousepos, desired)
Example #23
Source File: playback.py From xbmc with GNU General Public License v3.0 | 3 votes |
def _Input(mousex=0, mousey=0, click=0, keys=None, delay='0.2'): import pyautogui '''Control the user's mouse and/or keyboard. Arguments: mousex, mousey - x, y co-ordinates from top left of screen keys - list of keys to press or single key ''' g = Globals() screenWidth, screenHeight = pyautogui.size() mousex = int(screenWidth / 2) if mousex == -1 else mousex mousey = int(screenHeight / 2) if mousey == -1 else mousey exit_cmd = [('alt', 'f4'), ('ctrl', 'shift', 'q'), ('command', 'q')][(g.platform & -g.platform).bit_length() - 1] if keys: if '{EX}' in keys: pyautogui.hotkey(*exit_cmd) else: pyautogui.press(keys, interval=delay) else: pyautogui.moveTo(mousex, mousey) if click: pyautogui.click(clicks=click) Log('Input command: Mouse(x={}, y={}, click={}), Keyboard({})'.format(mousex, mousey, click, keys))