def moveSpeed(self, location, seconds=0.3): """ Moves cursor to specified ``Location`` over ``seconds``. If ``seconds`` is 0, moves the cursor immediately. Used for smooth somewhat-human-like motion. """ original_location = mouse.get_position() mouse.move(location.x, location.y, duration=seconds) if mouse.get_position( ) == original_location and original_location != location.getTuple(): raise IOError(""" Unable to move mouse cursor. This may happen if you're trying to automate a program running as Administrator with a script running as a non-elevated user. """)
def move(self, loc, yoff=None): """ Moves cursor to specified location. Accepts the following arguments: * ``move(loc)`` - Move cursor to ``Location`` * ``move(xoff, yoff) - Move cursor to offset from current location """ from .Geometry import Location self._lock.acquire() if isinstance(loc, Location): mouse.move(loc.x, loc.y) else: mouse.move(loc, yoff) self._last_position = loc self._lock.release()
def move(self, loc, yoff=None): """ Moves cursor to specified location. Accepts the following arguments: * ``move(loc)`` - Move cursor to ``Location`` * ``move(xoff, yoff)`` - Move cursor to offset from current location """ from .Geometry import Location self._lock.acquire() if isinstance(loc, Location): mouse.move(loc.x, loc.y) elif yoff is not None: xoff = loc mouse.move(xoff, yoff) else: raise ValueError( "Invalid argument. Expected either move(loc) or move(xoff, yoff)." ) self._last_position = loc self._lock.release()
def test_move(self): mouse.move(0, 0) self.assertEqual(mouse.os_mouse.get_position(), (0, 0)) mouse.move(100, 500) self.assertEqual(mouse.os_mouse.get_position(), (100, 500)) mouse.move(1, 2, False) self.assertEqual(mouse.os_mouse.get_position(), (101, 502)) mouse.move(0, 0) mouse.move(100, 499, True, duration=0.01) self.assertEqual(mouse.os_mouse.get_position(), (100, 499)) mouse.move(100, 1, False, duration=0.01) self.assertEqual(mouse.os_mouse.get_position(), (200, 500)) mouse.move(0, 0, False, duration=0.01) self.assertEqual(mouse.os_mouse.get_position(), (200, 500))
def do_GET(self): self.send_response(200, message='OK') if self.path == '/control': self.send_response(200, message='OK') control = self.headers._headers[0][1] if control == 'resume': keyboard.send('play/pause media') elif control == 'volup': keyboard.send('volume up') elif control == 'bfrtrack': keyboard.send('previous track') elif control == 'voltar': RequestHandler.open_deezer() keyboard.send('ctrl+left') elif control == 'avancar': RequestHandler.open_deezer() keyboard.send('ctrl+right') elif control == 'nxttrack': keyboard.send('next track') elif control == 'voldown': keyboard.send('volume down') elif control == 'mute': keyboard.send('volume mute') elif control == 'repeat': RequestHandler.open_deezer() keyboard.send('r') elif control == 'like': RequestHandler.open_deezer() keyboard.send('l') elif control == 'open': RequestHandler.open_deezer() elif control == '0.0': RequestHandler.open_deezer() keyboard.send('0') elif control == '1.0': RequestHandler.open_deezer() keyboard.send('1') elif control == '2.0': RequestHandler.open_deezer() keyboard.send('2') elif control == '3.0': RequestHandler.open_deezer() keyboard.send('3') elif control == '4.0': RequestHandler.open_deezer() keyboard.send('4') elif control == '5.0': RequestHandler.open_deezer() keyboard.send('5') elif control == '6.0': RequestHandler.open_deezer() keyboard.send('6') elif control == '7.0': RequestHandler.open_deezer() keyboard.send('7') elif control == '8.0': RequestHandler.open_deezer() keyboard.send('8') elif control == '9.0': RequestHandler.open_deezer() keyboard.send('9') elif control == 'openweb': webbrowser.open('http://deezer.com') if self.path == '/search': self.send_response(200, message='OK') print('open') control = self.headers._headers[0][1] RequestHandler.open_deezer() keyboard.send('S') keyboard.send('ctrl+a') keyboard.send('backspace') keyboard.write(control) keyboard.send('enter') time.sleep(2) mouse.move(width * firstWidth, height * firstHeight) mouse.click() mouse.move(width * secondWidth, height * secondHeight) mouse.click() self.send_response(200, message='OK')
def open_deezer(): win32gui.ShowWindow(DeezerWindow, 3) win32gui.SetForegroundWindow(DeezerWindow) mouse.move(100, 100) mouse.click()
def move(self, location): """ Moves cursor to specified ``Location`` """ mouse.move(location.x, location.y)
def test_move(self): mouse.move(0, 0) self.assertEqual(mouse._os_mouse.get_position(), (0, 0)) mouse.move(100, 500) self.assertEqual(mouse._os_mouse.get_position(), (100, 500)) mouse.move(1, 2, False) self.assertEqual(mouse._os_mouse.get_position(), (101, 502)) mouse.move(0, 0) mouse.move(100, 499, True, duration=0.01) self.assertEqual(mouse._os_mouse.get_position(), (100, 499)) mouse.move(100, 1, False, duration=0.01) self.assertEqual(mouse._os_mouse.get_position(), (200, 500)) mouse.move(0, 0, False, duration=0.01) self.assertEqual(mouse._os_mouse.get_position(), (200, 500))
def move(self, x, y): if not remote_control: raise "Remote control is not available" mouse.move(x, y)