Exemplo n.º 1
0
class Robot(object):

    def __init__(self):
        self.mouse = PyMouse()
        self.keyboard = PyKeyboard()
        self.przyciskPSP2klawiatura = {'up': 'w', 'right': 'd', 'down': 's', 'left': 'a', 'triangle': self.keyboard.enter_key,
                                       'circle': 'f', 'cross': 'g', 'square': 'h', 'l': self.keyboard.control_r_key, 'r': self.keyboard.shift_r_key, 'start': 'k', 'select': 'l'}

    def reaguj(self, x, y, przyciskPSP2Stan):
        self.reaguj_mysz(x, y)
        self.reaguj_klawiatura(przyciskPSP2Stan)

    def reaguj_mysz(self, x, y):
        max_predkosc_kursora = 0.00000000000000000000000000000000000000000000000000001
        x += int((x / float(128)) * max_predkosc_kursora +
                 self.mouse.position()[0])
        y += int((y / float(128)) * max_predkosc_kursora +
                 self.mouse.position()[1])
        x, y = min(self.mouse.screen_size()[0], x), min(
            self.mouse.screen_size()[1], y)
        x, y = max(0, x), max(0, y)
        self.mouse.move(x, y)

    def reaguj_klawiatura(self, przyciskPSP2Stan):
        for przycisk_psp, czyWcisniety in przyciskPSP2Stan.iteritems():
            przycisk_klawiaturowy = self.przyciskPSP2klawiatura[przycisk_psp]
            if czyWcisniety == '1':
                if przycisk_klawiaturowy == 'g':
                    self.mouse.click(*self.mouse.position())
                    break
                self.keyboard.press_key(przycisk_klawiaturowy)
            else:
                self.keyboard.release_key(przycisk_klawiaturowy)
Exemplo n.º 2
0
class MouseController:
    """
    鼠标控制器
    """
    def __init__(self):
        self.m = PyMouse()

    def position(self):
        print('鼠标当前位置是:%s,%s' % self.m.position())

    def click(self, x, y, button=1, times=1):
        if button == 2:
            self.rclick(x, y)
        else:
            self.lclick(x, y, times)
        self.position()

    def move(self, x, y):
        self.m.move(x, y)
        print('mouse move to (%d,%d)' % (x, y))

    def lclick(self, x, y, times=1):
        self.m.click(x, y, 1, times)
        print('mouse lclick on (%d,%d)' % (x, y))

    def rclick(self, x, y):
        self.m.press(x, y, 2)
        time.sleep(0.1)
        self.m.release(x, y, 2)
        print('mouse rclick on (%d,%d)' % (x, y))
Exemplo n.º 3
0
class MenuOjoData:

    DEGREEE_PATTERN = r"(?P<degree_data>[+-]\d{2})"

    def __init__(self):
        self.driver = PantojoBluetoothReceiver()
        self.pipes = [PantojoRealDataPipe()]
        self.mouse = PyMouse()
        (self.x_max, self.y_max) = self.mouse.screen_size()
        self.degree = re.compile(self.DEGREEE_PATTERN, re.VERBOSE)

    def open(self):
        self.driver.open()

    def recv(self):
        data = self.driver.recv()
        for pipe in self.pipes:
            data = pipe.apply(data)
        matched = self.degree.match(data)
        if matched:
            valor = int(data)
        (x, y) = self.mouse.position()
        if (valor != 0):
            #asumo que se mueve de a 15
            mov = (self.x_max / 7) * (valor / 15) + x
            self.mouse.move(mov, y)
        else:
            self.mouse.move(self.x_max / 2, y)
        return data

    def close(self):
        self.driver.close()
Exemplo n.º 4
0
    def restart1(self, x, y):
        self.showAhead()
        dm = self.dm_manager
        dm.setPath(u"c:/anjianScript/通用经验")
        for i in range(0, 10):
            print 'here'
            # intX,intY = FindPic(dm,x,y,x+90,y+50,u"启动.bmp|启动1.bmp","050505",0.8,0)
            intX, intY = FindPic(dm, x, y, x + 90, y + 50, u"启动.bmp", "050505",
                                 0.8, 0)
            if intX > 0:
                print 'find qidong'
                dm.moveto(intX, intY)
                dm.leftclick()
                sleep(1.000)
                mouse = PyMouse()
                mouse.move(1, 1)
                sleep(1.500)
                break
            intX, intY = FindPic(dm, x, y, x + 90, y + 50, u"关闭.bmp", "050505",
                                 0.8, 0)
            if intX > 0:
                dm.moveto(intX, intY)
                dm.leftclick()
                sleep(.500)
                dm.moveto(0, 0)
                sleep(4.0)

                continue
            sleep(2.0)
Exemplo n.º 5
0
def start_app():
    print(
        time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) +
        ' start ' + app_name)
    os.chdir(app_dir)
    win32api.ShellExecute(0, 'open', app_name, '', '', 1)
    m = PyMouse()
    # time.sleep(2);
    # hwnd=win32gui.FindWindow(0,u'振动数据采集与分析系统');
    # print(hwnd);
    time.sleep(2)
    # #win32gui.SetForegroundWindow(hwnd);
    # #win32api.SetCursorPos((x_test,y_test));
    # #win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN|win32con.MOUSEEVENTF_LEFTUP,0,0,0,0);
    m.move(x_test, y_test)
    time.sleep(1)
    # #win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN|win32con.MOUSEEVENTF_LEFTUP,0,0,0,0);
    m.click(x_test, y_test)
    # #m.click(x_test,y_test);
    # #time.sleep(sleep2_time);
    # # time.sleep(5);
    # m.move(x_start,y_start);
    # # time.sleep(1);
    # # m.click(x_start,y_start,1);
    # # m.click(x_start,y_start,1);
    # ctypes.windll.user32.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN+win32con.MOUSEEVENTF_LEFTUP,0,0,0,0);
    # #ctypes.windll.user32.SetCursorPos((x_start,y_start));
    # ctypes.windll.user32.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN|win32con.MOUSEEVENTF_LEFTUP|win32con.MOUSEEVENTF_ABSOLUTE
    # 					,x_start,y_start,0,0);
    # SendInput(Mouse(win32con.MOUSEEVENTF_ABSOLUTE | win32con.MOUSEEVENTF_MOVE, x_start,y_start));
    # SendInput(Mouse( win32con.MOUSEEVENTF_LEFTDOWN |win32con.MOUSEEVENTF_ABSOLUTE, x_start,y_start));
    # SendInput(Mouse( win32con.MOUSEEVENTF_LEFTUP |win32con.MOUSEEVENTF_ABSOLUTE, x_start,y_start));
    timer = threading.Timer(running_interval, kill_app)
    timer.start()
Exemplo n.º 6
0
def drag(source, dest, speed=1000):
    """
    Simulates a smooth mouse drag

    Args:
        source (int, int) : location (x,y) to start the drag, in screen 
            coordinates
        dest (int, int) : location (x,y) to end the drag, in screen 
            coordinates
        speed (int) : rate at which to execute the drag, in pixels/second
    """
    m = PyMouse()
    m.press(*source)

    time.sleep(0.1)

    # number of intermediate movements to make for our given speed
    npoints = int(sqrt((dest[0]-source[0])**2 + (dest[1]-source[1])**2 ) / (speed/1000))
    for i in range(npoints):
        x = int(source[0] + ((dest[0]-source[0])/npoints)*i)
        y = int(source[1] + ((dest[1]-source[1])/npoints)*i)
        m.move(x,y)
        time.sleep(0.001)

    m.release(*dest)
Exemplo n.º 7
0
        def click_function(inp, click_type):

            inp = inp.split()
            x, y = inp[0].split(',')
            x = float(do(x))
            y = float(do(y))
            mouse = PyMouse()
            screen_size_value = mouse.screen_size()

            if x > screen_size_value[0] or y > screen_size_value[1]:
                raise RuntimeError('__________ERROR: click coordinates to big')

            if click_type not in [1, 2, 3]:
                raise RuntimeError(
                    'internal function error: invalid click type')

            if not self.booltesting:

                if click_type == 3:
                    mouse.move(x, y)
                else:
                    mouse.click(x, y, click_type)

                if len(inp) == 2:
                    time.sleep(float(do(inp[1])))
            '''
Exemplo n.º 8
0
def move():
    deadzone_x = 200
    deadzone_y = 200
    key_delay = 0.4

    mouse = PyMouse()

    PORT = "/dev/ttyACM1"
    #~ PORT = "/dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_9900023431864e45001210060000003700000000cc4d28bd-if01"
    BAUD = 115200

    s = serial.Serial(PORT)
    s.baudrate = BAUD
    s.parity = serial.PARITY_NONE
    s.databits = serial.EIGHTBITS
    s.stopbits = serial.STOPBITS_ONE

    while True:
        data = s.readline().decode('UTF-8')
        data_list = data.rstrip().split(' ')
        try:
            x, y, z, a, b = data_list
            x_mapped = arduino_map(int(x), -1024, 1024, -960, 960)
            y_mapped = arduino_map(int(y), -1024, 1024, -540, 540)

            x_centre = 960
            y_centre = 540

            print(x_mapped, y_mapped)
            mouse.move(x_centre + x_mapped, y_centre + y_mapped)

        except:
            pass

    s.close()
Exemplo n.º 9
0
def mouse_click():
    m = PyMouse()
    # a = m.position()  # 获取当前坐标的位置
    # m.move(50, 500)  # 鼠标移动到(x,y)位置
    # a = m.position()
    m.click(50, 50)  # 移动并且在(x,y)位置左击
    m.move(500, 500)
Exemplo n.º 10
0
def netflix_continue():
    m = PyMouse()
    x, y = m.screen_size()
    m.click(x/2, y/2-60)
    time.sleep(0.33)
    m.move(x/2, 0)
    return ""
Exemplo n.º 11
0
def netflix_play():
    m = PyMouse()
    m.move(150, 640)
    time.sleep(0.25)
    m.click(150, 640)
    m.move(300, 0)
    return ""
Exemplo n.º 12
0
class WinMouseControl():
    
    mouseObject=''
    def __init__(self):
        self.mouseObject=PyMouse()
        print "mouse init success"
        pass
    
    def __del__(self):
        pass
    
    def mouseMove(self,x,y,button=None):
        self.mouseObject.move(x, y)
        return 0
    
    def mouseClick(self,x,y,button):
        self.mouseObject.click(x, y, button)   #button:1 left, button2: middle button3:right
        return 0
    
    def mousePress(self,x,y,button):
        self.mouseObject.press(x, y, button)   #button:1 left, button2: middle button3:right
        return 0
    
    def mouseRelease(self,x,y,button):
        self.mouseObject.release(x, y, button)   #button:1 left, button2: middle button3:right
        return 0
Exemplo n.º 13
0
def move_from_to(x1, y1, x2, y2):
    y = int((y2 - y1) / 20)
    x = int((x2 - x1) / 20)
    m = PyMouse()
    m.move(x1, y1)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    num = 1
    while num <= 18:
        num += 1
        x2 = x1 + x * num
        y2 = y1 + y * num
        time.sleep(0.05)
        m.move(x2, y2)
        print("moveto  %d  %d" % (x2, y2))
    time.sleep(0.5)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    return


#
# x1=700
# y1=700
# x2=100
# y2=100
# y=int((y2-y1)/10)
# x=int((x2-x1)/10)
# num = 1
# while num<10:
#     num +=1
#     x2 = x1 + x * num
#     y2 = y1 + y * num
#     print("num %d"%num)
#     print("x2 %d y2 %d"%(x2,y2))
Exemplo n.º 14
0
def main():
    mouse = PyMouse()

    # 	wm = cwiid.Wiimote("00:25:A0:CE:3B:6D")
    wm = cwiid.Wiimote()
    wm.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_IR

    X, x = calibrate(wm)
    trans = getTransMatrix(x, X)

    screen = mouse.screen_size()
    lastTime = time.time()
    o = None

    state = NEUTRAL

    print("battery: %f%%" % (float(wm.state["battery"]) / float(cwiid.BATTERY_MAX) * 100.0))

    window = pygame.display.set_mode((200, 150))

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit(0)

        pos = getWiiPointNonBlock(wm)

        if pos != None:
            ipt = numpy.matrix([[pos.x], [pos.y], [1]])
            optMat = trans.I * ipt
            o = Point(optMat[0] / optMat[2], optMat[1] / optMat[2])

            if o.x < 0:
                o.x = 0
            elif o.x >= screen[0]:
                o.x = screen[0] - 1

            if o.y < 0:
                o.y = 0
            elif o.y >= screen[1]:
                o.y = screen[1] - 1

            if state == NEUTRAL:
                state = FIRST_INPUT
                lastTime = time.time()
            elif state == FIRST_INPUT:
                if time.time() - FIRST_INPUT_TO_PRESSED > lastTime:
                    mouse.press(o.x, o.y)
                    state = PRESSED
            elif state == PRESSED:
                mouse.move(o.x, o.y)

        if state == FIRST_INPUT and pos == None and time.time() - FIRST_INPUT_TO_PRESSED < lastTime:
            mouse.click(o.x, o.y)
            time.sleep(0.2)
            state = NEUTRAL

        if state == PRESSED and pos == None and time.time() - 1 > lastTime:
            mouse.release(o.x, o.y)
            state = NEUTRAL
Exemplo n.º 15
0
def slide_down(x, y, h):
    m = PyMouse()
    m.move(x, y)
    m.press(x, y, 1)
    m.move(x, y + h)
    m.release(x, y + h, 1)
    return
Exemplo n.º 16
0
class Mouse:
    def __init__(self):
        import autopy
        from pymouse import PyMouse

        self.m1 = autopy.mouse
        self.loc = [self.m1.get_pos()[0],self.m1.get_pos()[1]]
        self.m = PyMouse()
        self.m.move(self.loc[0], self.loc[1])

    def move(self,direction):
        #Move mouse
        self.loc[0] += direction[0]
        self.loc[1] += direction[1]
        #FIXME: Support multiple displays
        #Check horizontal bounds
        self.loc[0] = min(self.loc[0],3600)#self.m.screen_size()[0])
        self.loc[0] = max(self.loc[0],0)
        #Check vertical bounds
        self.loc[1] = min(self.loc[1],self.m.screen_size()[1])
        self.loc[1] = max(self.loc[1],0)
        self.m.move(int(self.loc[0]), int(self.loc[1]))

    def click(self,button):
        self.m1.click(button)
    def draw_arc(self, window):
        #self.drawing_area.window.draw_arc(self.context, False, self._x, self._y, 70, 70, 0, 360*64)
	window.set_keep_below(True)
	window.hide()
	m = PyMouse()
	m.move(self._x, self._y)
	m.click(self._x, self._y, 1)
Exemplo n.º 18
0
def main(callback=None):
    m = PyMouse()

    def exit_handler():
        for button in range(3):
            m.release(0, 0, button + 1)

    atexit.register(exit_handler)
    width, height = m.screen_size()
    width /= 2
    height /= 2
    old_buttons = 0
    for f in falcon():
        x, y, z = xyz(f.getPosition())
        new_buttons = buttons(f)
        xx = int(width + x * width // 0.03)
        yy = int(height - y * height // 0.03)
        m.move(xx, yy)
        if callback:
            callback(f, xx, yy)
        for button in range(3):
            if new_buttons & 1 << button and not old_buttons & 1 << button:
                m.press(xx, yy, button + 1)
            if not new_buttons & 1 << button and old_buttons & 1 << button:
                m.release(xx, yy, button + 1)
        if new_buttons & 1 << 3:
            print("â–¶ pressed; exiting")
            break
        old_buttons = new_buttons
        time.sleep(1 / 60)
Exemplo n.º 19
0
 def test_move(self):
     for size in screen_sizes:
         with Display(visible=VISIBLE, size=size):
             mouse = PyMouse()
             for p in positions:
                 mouse.move(*p)
                 eq_(expect_pos(p, size), mouse.position())
Exemplo n.º 20
0
    def _move_slider(self, offset_slider_x=50, offset_window_y=106):
        # 获取滑块的位置
        loc_slider = self.driver.find_element_by_id('nc_1_n1z').location
        # 获取滑块的尺寸
        size_slider = self.driver.find_element_by_id('nc_1_n1z').size

        # 获取滑框的位置
        loc_frame = self.driver.find_element_by_id('nc_1__scale_text').location
        # 获取滑框的尺寸
        size_frame = self.driver.find_element_by_id('nc_1__scale_text').size
        # 滑块需要滑动的距离
        slider_dis = size_frame["width"] - size_slider[
            "width"] + offset_slider_x
        # 滑块的y坐标值
        slider_y = loc_slider["y"]
        # 滑块开始滑动的位置
        slider_x0 = loc_slider["x"]
        slider_y0 = loc_slider["y"]
        # print('开始滑动滑块... ...')
        xTrack = []
        mid = slider_dis * 3 / 4 + slider_x0
        current = slider_x0
        t = random.uniform(0.4, 0.5)
        # print('t:' + str(t))
        v = 0
        loc_end = slider_x0 + slider_dis
        while current < loc_end:
            if current < mid:
                # a = 2
                a = 2
            else:
                # a = -3
                a = 1
            v0 = v
            v = v0 + a * t
            move = v0 * t + 1 / 2 * a * t * t
            # print('move_distance:' + str(move))
            current += move
            # print('current_location:' + str(current))
            # 移动的距离上取整,因为移动时在windows上会四舍五入
            # move = math.ceil(move)
            # 四舍五入
            # move = round(move)
            # xTrack.append(move)
            current = round(current)
            xTrack.append(current)
        mouse_x0 = slider_x0 + size_slider["width"] / 2
        mouse_y0 = slider_y0 + size_slider["height"] / 2 + offset_window_y
        # 移动到滑块位置
        pyautogui.moveTo(mouse_x0, mouse_y0, duration=0.25)
        pyautogui.moveTo()
        # 鼠标左键按下
        pyautogui.mouseDown(mouse_x0, mouse_y0, button='left', duration=0.15)
        mouse = PyMouse()
        for num in xTrack:
            # print('移动的距离%d' % num)
            # ActionChains(self.driver).move_by_offset(xoffset=num, yoffset=0).perform()
            mouse.move(int(num), int(mouse_y0))
        # 抬起鼠标
        pyautogui.mouseUp()
Exemplo n.º 21
0
def move_down():
    m = PyMouse()
    xt=random.randint(1400, 1600)
    yt=random.randint(700, 800)

    m.position()
    m.move(xt, yt)
def move ():
    deadzone_x = 200
    deadzone_y = 200
    key_delay = 0.4
    
    mouse = PyMouse()
    
    PORT = "/dev/ttyACM1"
    #~ PORT = "/dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_9900023431864e45001210060000003700000000cc4d28bd-if01"
    BAUD = 115200
    
    s = serial.Serial(PORT)
    s.baudrate = BAUD
    s.parity = serial.PARITY_NONE
    s.databits = serial.EIGHTBITS
    s.stopbits = serial.STOPBITS_ONE
    
    while True:
        data = s.readline().decode('UTF-8')
        data_list = data.rstrip().split(' ')
        try:
            x, y, z, a, b = data_list
            x_mapped = arduino_map(int(x), -1024, 1024, -960, 960)
            y_mapped = arduino_map(int(y), -1024, 1024, -540, 540)
            
            x_centre = 960
            y_centre = 540
        
            print(x_mapped, y_mapped)
            mouse.move(x_centre + x_mapped, y_centre + y_mapped)
        
        except:
            pass
        
    s.close()
Exemplo n.º 23
0
 def test_move(self):
     for size in screen_sizes:
         with Display(visible=VISIBLE, size=size):
             mouse = PyMouse()
             for p in positions:
                 mouse.move(*p)
                 eq_(expect_pos(p, size), mouse.position())
Exemplo n.º 24
0
class Mouse:
    def __init__(self):
        self.m = PyMouse()
        # self.suppress_xlib_output(2)

    def get_mouse_position(self):
        return self.m.position()

    def press(self, x, y, button=1):
        self.m.press(x, y, button)

    def release(self, x, y, button=1):
        self.m.release(x, y, button)

    def click(self, x, y, button=1):
        self.m.click(x, y, button)

    def move_to(self, x, y):
        self.m.move(x, y)

    @staticmethod
    def suppress_xlib_output(num):
        for i in range(num):
            print '\r\033[1A' + 46 * ' ',
        print
Exemplo n.º 25
0
def mouse_simulate():
    try:
        class event(PyMouseEvent):
            def move(self, x, y):
                pass

            def click(self, x, y, button, press):
                if press:
                    print("Mouse pressed at", x, y, "with button", button)
                else:
                    print("Mouse released at", x, y, "with button", button)
        e = event()
        e.start()

    except ImportError:
        print("Mouse events are not yet supported on your platform")

    m = PyMouse()

    t_corr = (1173,313)
    i_pos = t_corr
    m.move(i_pos[0] , i_pos[1])

    while(True):
        if is_run is False:
            time.sleep(1)
        else:
            time.sleep(0.2)
            m.click(i_pos[0], i_pos[1])

    try:
        e.stop()
    except:
        pass
Exemplo n.º 26
0
def realtimemouse():
    # m.click(x, y, button, n)
    # 鼠标点击
    # x, y是坐标位置
    # buttong 1表示左键,2 表示点击右键
    # n点击次数,默认是1次,2表示双击

    # time_each_break2 = time_two.value

    k = 0
    m = PyMouse()

    # 不断地从存储中获取数据,一旦有新的数据,就移动鼠标,完成实时鼠标跟随眼动的效果
    while True:
        if (os.path.exists('D:/eyetrack/txt_x_mouse/' + str(k) + '.txt') == True) and (
                os.path.exists('D:/eyetrack/txt_y_mouse/' + str(k) + '.txt') == True):

            file_handle_x = open('D:/eyetrack/txt_x_mouse/' + str(k) + '.txt', mode='r')
            file_handle_y = open('D:/eyetrack/txt_y_mouse/' + str(k) + '.txt', mode='r')

            point_x_str_read = int(file_handle_x.read())
            point_y_str_read = int(file_handle_y.read())
            m.move(point_x_str_read, point_y_str_read - 150)  # 减掉150是测试时发现的误差
            k = k + 1

        else:
            continue
Exemplo n.º 27
0
class Server():
	def __init__(self):
		self.running = True
		self.socket = None
		self.client_socket = None
		self.client_address = None
		self.mouse = PyMouse()

	def run(self):
		self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		self.socket.bind(('localhost', PORT_NUMBER))
		self.socket.listen(1) # max 1 connection for now
		print('Waiting for connections...')
		self.client_socket, self.client_address = self.socket.accept()
		print('connected to ' + str(self.client_address))
		threading.Thread(target=self.receive).start()
		#self.client_socket.send(str(IMAGE_SIZE).encode()) #sending dimensions
		while self.running:
			self.sendcap()

	def sendcap(self):
		ss = capscreen()
		self.client_socket.send(ss)

	def receive(self):
		while self.running:
			mouse_location = (self.client_socket.recv(1024).decode())
			print(mouse_location)
			if ',' in mouse_location:
				x, y = map(float, mouse_location.split(','))
				self.mouse.move(int(x), int(y))

	def kill(self):
		self.running = False
		self.client_socket.close()
Exemplo n.º 28
0
class Mouse:

	@property
	def vis(self):
		return self._vis

	def __init__(self,vis):
		self._vis = vis
		self.pm = PM()

	""" Takes a board coordinate (x,y) and uses self._vis to calculate the
	screen coordinates to click there. Then it waits 5.7 ms, and takes a 
	screenshot"""
	def left_click(self,x,y):
		#print "clicking at",x,y
		x0, y0 = self.vis.edge_coords
		x1, y1 = (x0 + 8 + x * 16, y0 + 8 + y * 16)
		self.pm.move(x1,y1)
		self.pm.click(x1,y1,1)
		#time.sleep(0.25)
	
	def right_click(self,x,y):
		x0, y0 = self.vis.edge_coords
		x1, y1 = (x0 + 8 + x * 16, y0 + 8 + y * 16)
		self.pm.click(x1,y1,2)
		#time.sleep(0.05)

	""" Uses self._vis to determine the position of the smiley reset button"""
	def reset_board(self):
		(resx, resy) = self.vis.get_reset()
		self.pm.move(resx,resy)
		self.pm.press(resx,resy,1)
		time.sleep(0.5)
		self.pm.release(resx,resy,1)
Exemplo n.º 29
0
def main():
    #Initialize positions
    L_pos = [(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0)]
    R_pos = [(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0)]

    #initialize controller, mouse, and keyboard
    controller = Leap.Controller()
    m = PyMouse()
    x_dim, y_dim = m.screen_size()
    k = PyKeyboard()
    
    
    
    
    #print positions every half second
    looping = True
    while looping:
        #update hand positions
        R_pos = update(controller,0);
        L_pos = update(controller,1);

        #Track mouse to right index finger
        #press if z is negative
        pressed = False
        mouseX = int(R_pos[1][0] * x_dim / 200.0 + x_dim / 2)
        if mouseX < 0:
            mouseX = 0
        elif mouseX > x_dim:
            mouseX = x_dim - 1

        mouseY = int(y_dim - ((R_pos[1][1] - 200) * y_dim / 100.0))
        if mouseY < 0:
            mouseY = 0
        if mouseY > y_dim - 1:
            mouseY = y_dim - 1

        mouseZ = R_pos[1][2]

        if mouseZ > 10:
            if pressed:
                m.release(mouseX,mouseY,1)
                pressed = False
            else:
                m.move(mouseX,mouseY)
        if mouseZ < -10:
            if not pressed:
                m.press(mouseX,mouseY,1)
                pressed = True
            else:
                #m.move(mouseX,mouseY)
                pass
                
        
        #End if either index finger is above the controller
        for positions in [L_pos, R_pos]:
            if (positions[1][0] < 50 and positions[1][0] > -50) and \
                (positions[1][1] < 50 and positions[1][1] > 0) and \
                (positions[1][2] < 50 and positions[1][2] > -50):
                looping = False
Exemplo n.º 30
0
def clickOnCorner():
    m = PyMouse()
    x = 1438
    y = 2558
    m.move(x, y)
    m.click(x, y)  #the third argument "1" represents the mouse button
    m.press(x, y)  #mouse button press
    m.release(x, y)  #mouse button release
Exemplo n.º 31
0
 def test_move(self):
     for size in screen_sizes:
         with Display(visible=VISIBLE, size=size) as d:
             time.sleep(0.5)
             mouse = PyMouse(display=d.new_display_var)
             for p in positions:
                 mouse.move(*p)
                 eq_(expect_pos(p, size), mouse.position())
Exemplo n.º 32
0
 def moveMouse(self, myX,myY):
     try:
         from pymouse import PyMouse
         m = PyMouse()
         m.position()
         m.move(myX, myY)
     except Exception as e:
         raise e
Exemplo n.º 33
0
class Mouse(object):
    def __init__(self):
        self.m = PyMouse()

    def click(self, x, y):
        curr_pos = self.m.position()
        self.m.click(x, y, 1)
        self.m.move(curr_pos[0], curr_pos[1])
	def ut_showMouseLoc(self):
		points = [(120,120), (600,480), (500,1000), (800,200)]
		m = PyMouse() # make mouse object
		for point in points:
			print "Moving to: ", point
			m.move(point[0],point[1])
			print "The Mouse is at:", m.position()
		print "Test complete!"	
Exemplo n.º 35
0
def op_mouse(x, y):
    from pymouse import PyMouse
    mouse = PyMouse()

    #print "move to point(%d, %d) and click ..." % (x, y)
    x0, y0 = mouse.position()  # save the old position
    mouse.move(x, y)
    mouse.click(x, y)
    mouse.move(x0, y0)  # move back
Exemplo n.º 36
0
class EasyMonkey:
    def __init__(self):
        self.mouse = PyMouse()
        self.keyboard = PyKeyboard()
        self.sleep = 0.5
        time.sleep(1)

    # 模拟鼠标左键单击
    def left_click(self, x, y):
        self.mouse.move(x, y)
        self.mouse.click(x, y)
        print("在(%s,%s)位置进行了鼠标左键单击操作" % (x, y))
        time.sleep(self.sleep)
        return x, y

    # 模拟鼠标左键双击
    def left_doubleclick(self, x, y):
        self.mouse.move(x, y)
        self.mouse.click(x, y, button=1, n=2)
        print("在(%s,%s)位置进行了鼠标左键双击操作" % (x, y))
        time.sleep(self.sleep)
        return x, y

    # 模拟鼠标右键单击
    def right_click(self, x, y):
        self.mouse.move(x, y)
        self.mouse.click(x, y, button=2, n=1)
        print("在(%s,%s)位置进行了鼠标右键单击操作" % (x, y))
        self.mouse.click(x, y, button=1, n=1)
        time.sleep(self.sleep)
        return x, y

    # 模拟使用键盘随机按键
    def enter_key(self, x, y):
        self.mouse.move(x, y)
        keys = [
            "a", "b", self.keyboard.numpad_keys[2],
            self.keyboard.numpad_keys[4]
        ]
        index = random.randint(0, (len(keys) - 1))
        key = keys[index]
        self.keyboard.press_key(key)
        self.keyboard.release_key(key)
        print("在(%s,%s)位置进行了键盘随机按键操作" % (x, y))
        time.sleep(self.sleep)
        return x, y

    # 模拟使用键盘产生随机输入
    def input_key(self, x, y):
        self.mouse.move(x, y)
        strs = ["123", "456"]
        index = random.randint(0, (len(strs) - 1))
        str0 = strs[index]
        self.keyboard.type_string(str0)
        print("在(%s,%s)位置进行了键盘产生随机输入操作" % (x, y))
        time.sleep(self.sleep)
        return x, y
Exemplo n.º 37
0
def click(p, t = 0.6):
    x = p.x
    y = p.y
    m = PyMouse()
    m.move(x, y)
    m.click(x, y, 1)
#    m.press(x, y)
#    m.release(x, y)
    time.sleep(t)
Exemplo n.º 38
0
class MouseController(object):
    """Control mouse."""
    def __init__(self):
        self._mouse_controller = PyMouse()
        self._delay_before = 0
        self._delay_after = 0

    @property
    def delay_before(self):
        """Get delay before mouse click.

        :return: delay in seconds
        """
        return self._delay_before

    @delay_before.setter
    def delay_before(self, value):
        """Set delay before mouse click.

        :return: delay in seconds
        """
        self._delay_before = value

    @property
    def delay_after(self):
        """Get delay after mouse click.

        :return: delay in seconds
        """
        return self._delay_after

    @delay_after.setter
    def delay_after(self, value):
        """Set delay after mouse click.

        :return: delay in seconds
        """
        self._delay_after = value

    def set_position(self, position):
        """Set mouse position to given position.

        :param position: position where the mouse will be moved
        :type position: instance of the Point class
        """
        self._mouse_controller.move(position.x, position.y)

    def left_click(self):
        """Click left mouse button on the actual position."""
        if self._delay_before != 0:
            time.sleep(self._delay_before)

        # click on current position
        self._mouse_controller.click(*self._mouse_controller.position())

        if self._delay_after != 0:
            time.sleep(self._delay_after)
Exemplo n.º 39
0
def listen_mouse():
    m = PyMouse()
    while 1:
        data = sock.recv(16)
        _pos = data
        _x = _pos.split('(')[1].split(',')[0]
        _y = _pos.split(' ')[1].split(')')[0]
        m.move(int(_x), int(_y))
        sleep(0.1)
Exemplo n.º 40
0
def main():
    mouse = PyMouse()

    #	wm = cwiid.Wiimote("00:25:A0:CE:3B:6D")
    wm = cwiid.Wiimote()
    wm.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_IR

    X, x = calibrate(wm)
    trans = getTransMatrix(x, X)

    screen = mouse.screen_size()
    lastTime = time.time()
    o = None
    points = []

    print('battery: %f%%' %
          (float(wm.state['battery']) / float(cwiid.BATTERY_MAX) * 100.0))

    window = pygame.display.set_mode((200, 150))

    while True:
        for event in pygame.event.get():
            if (event.type == pygame.QUIT):
                sys.exit(0)

        while (time.time() < lastTime + 0.01):
            pos = getWiiPointNonBlock(wm)

            if (pos != None):
                points.append(pos)

        print(len(points))

        if (len(points) > 0):
            pos = avPoints(points)

            ipt = numpy.matrix([[pos.x], [pos.y], [1]])
            optMat = trans.I * ipt
            o = Point(optMat[0] / optMat[2], optMat[1] / optMat[2])

            if (o.x < 0):
                o.x = 0
            elif (o.x >= screen[0]):
                o.x = screen[0] - 1

            if (o.y < 0):
                o.y = 0
            elif (o.y >= screen[1]):
                o.y = screen[1] - 1

            mouse.move(o.x, o.y)

            if (wm.state['buttons'] & cwiid.BTN_A):
                mouse.click(o.x, o.y)

        lastTime = time.time()
        points = []
Exemplo n.º 41
0
def listen_mouse():
    m = PyMouse()
    while 1:
        data = sock.recv(16)
        _pos = data
        _x = _pos.split('(')[1].split(',')[0]
        _y = _pos.split(' ')[1].split(')')[0]
        m.move(int(_x), int(_y))
        sleep(0.1)
Exemplo n.º 42
0
 def slide_down(self, x, y, h):
     log.log("move and location x,y '%s, %s' " % (x, y))
     m = PyMouse()
     m.move(x, y)
     m.press(x, y, 1)
     time.sleep(1)
     m.move(x, y + h)
     m.release(x, y + h, 1)
     return
Exemplo n.º 43
0
def main():
	mouse = PyMouse()

#	wm = cwiid.Wiimote("00:25:A0:CE:3B:6D")
	wm = cwiid.Wiimote()
	wm.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_IR

	X,x = calibrate(wm)
	trans = getTransMatrix(x, X)

	screen = mouse.screen_size()
	lastTime = time.time()
	o = None
	points = []

	print('battery: %f%%' % (float(wm.state['battery']) / float(cwiid.BATTERY_MAX) * 100.0))

	window = pygame.display.set_mode((200, 150))

	while True:
		for event in pygame.event.get():
			if (event.type == pygame.QUIT):
				sys.exit(0)

		while (time.time() < lastTime + 0.01):
			pos = getWiiPointNonBlock(wm)

			if (pos != None):
				points.append(pos)

		print(len(points))

		if (len(points) > 0):
			pos = avPoints(points)

			ipt = numpy.matrix([[pos.x], [pos.y], [1]])
			optMat = trans.I * ipt
			o = Point(optMat[0] / optMat[2], optMat[1] / optMat[2])

			if (o.x < 0):
				o.x = 0
			elif (o.x >= screen[0]):
				o.x = screen[0] - 1

			if (o.y < 0):
				o.y = 0
			elif (o.y >= screen[1]):
				o.y = screen[1] - 1

			mouse.move(o.x, o.y)

			if (wm.state['buttons'] & cwiid.BTN_A):
				mouse.click(o.x, o.y)

		lastTime = time.time()
		points = []
Exemplo n.º 44
0
 def test_move(self):
     for size in screen_sizes:
         try:
             disp = Display(visible=VISIBLE, size=size).start()
             mouse = PyMouse()
             for p in positions:
                 mouse.move(*p)
                 eq_(expect_pos(p, size), mouse.position())
         finally:
             disp.stop()
Exemplo n.º 45
0
def zoom_out():
    m = PyMouse()
    (x, y) = m.position()
    m.move(700, 700)
    press()
    # m.move(200, 100)
    # m.move(300, 100)
    # m.move(400, 100)
    # m.move(500, 100)
    release()
Exemplo n.º 46
0
def move(point):
    """
    Moves the mouse cursor to the provided location

    Args:
        point (int, int): location (x,y) of the screen to place the cursor
    """
    # wrapper just so we don't have to import pymouse separately
    m = PyMouse()
    m.move(*point)
Exemplo n.º 47
0
def slide_up(x, y, h):

    m = PyMouse()
    m.move(x, y)
    #m.press(x, y, 1)
    #m.move(x, y - h)
    #m.release(x, y - h, 1)
    win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, -h)

    return
Exemplo n.º 48
0
def draw():
    linedraw.draw_contours = draw_contours
    linedraw.draw_hatch = draw_hatch
    linedraw.hatch_size = hatch_size
    linedraw.contour_simplify = contour_simplify

    cache_name = get_cache_name()

    print(cache_name, input_path)

    try:
        file = open(cache_name, 'r')
        fc = file.read()
        lines = json.loads(fc)
        file.close()
    except FileNotFoundError:
        print("Unexpected error:", sys.exc_info()[0])
        file = open(cache_name, 'w')
        lines = linedraw.sketch(input_path)
        file.write(json.dumps(lines))
        file.close()

    mouse = PyMouse()

    mouse_x, mouse_y = mouse.position()

    time.sleep(delay)

    scale = 1

    def get_x(_x):
        return (_x * scale) + mouse_x

    def get_y(_y):
        return (_y * scale) + mouse_y

    def drag(_x, _y):
        # print("drag: {},{}".format(_x, _y))
        mouse.drag(_x, _y)

    for line in lines:

        start_x, start_y = line[0]

        mouse.press(get_x(start_x), get_y(start_y), 1)

        for (x, y) in line:
            time.sleep(speed)
            drag(get_x(x), get_y(y))

        end_x, end_y = line[len(line) - 1]

        mouse.release(get_x(end_x), get_y(end_y), 1)

    mouse.move(mouse_x, mouse_y)
Exemplo n.º 49
0
def run_CICFlowMeter():
    m = PyMouse()
    x, y = m.position()
    cmd = ['sudo ./CICFlowMeter']
    #open 3 app instances
    p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE)
    #p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE)
    #p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE)
    #separate the instances on the screen
    time.sleep(5)
    m.press(650,300,1) #move 1
    m.release(60,20)
    time.sleep(0.5)
    m.move(740,300)
    time.sleep(0.5)
    '''m.press(740,300,1) #move 2
    m.release(100,500)
    m.move(750,300)
    time.sleep(0.5)
    m.press(750,300,1) #move 3
    m.release(800,20)
    time.sleep(0.5)'''
    m.click(60,370) #set load1
    time.sleep(2)
    '''m.click(750,370) #set load2
    time.sleep(0.5)
    m.click(60,850) #set load3
    time.sleep(0.5)'''
    m.click(300,490)
    m.click(300,480) #set any
    time.sleep(0.25)
    '''m.click(790,490)
    time.sleep(0.25)
    m.click(790,480) #set any
    time.sleep(0.25)
    m.click(300,870)
    time.sleep(0.25)
    m.click(300,960) #set any
    time.sleep(0.25)'''
    s = time.time()
    m.click(60,410) #start 1
    time.sleep(0.25)
    '''m.click(740,400) #start 2
    time.sleep(0.5)
    m.click(30,878) #start 3'''

    '''inst1 = threading.Thread(target = run1, args=(m,s))
    inst2 = threading.Thread(target = run2, args=(m,s))
    inst3 = threading.Thread(target = run3, args=(m,s))'''

    '''inst1.start()
    inst2.start()
    inst3.start()'''

    p.wait()
Exemplo n.º 50
0
def click(point):
    """
    Simulates a mouse click

    Args:
        point (int,int) : location (x,y) of the screen to click
    """
    m = PyMouse()
    m.move(*point)
    m.press(*point)
    m.release(*point)
Exemplo n.º 51
0
def playback(binary_image, scale, tx, ty, sleep_duration_per_chord=0.02):
    m = PyMouse()
    for row_idx, row_data in enumerate(binary_image):
        y = int((scale * row_idx) + ty)
        chords = extract_chords(row_data)
        for c0, c1 in chords:
            x0 = int((scale * c0) + tx)
            x1 = int((scale * c1) + tx)
            m.move(x0, y)
            m.drag(x1, y)
        sleep(sleep_duration_per_chord * len(chords))
Exemplo n.º 52
0
class MouseRemote(AweRemPlugin):
    """
    Print "RedButton Triggered"
    """

    def activate(self):
        self.realMouse = PyMouse()
        self.handler = MouseHandler(self)
        self.info = {"title": "Mouse", "category": "utils",
                     "priority": 0}

    def getHandler(self):
        return self.handler

    def getInfo(self):
        return self.info

    def getIconPath(self, dpi):
        return ""

    def click(self, button, x=None, y=None):
        curx, cury = self.realMouse.position()
        if x is None:
            x = curx
        if y is None:
            y = cury
        self.realMouse.click(x, y, button)

    def press(self, button, x=None, y=None):
        curx, cury = self.realMouse.position()
        if x is None:
            x = curx
        if y is None:
            y = cury
        self.realMouse.press(x, y, button)

    def release(self, button, x=None, y=None):
        curx, cury = self.realMouse.position()
        if x is None:
            x = curx
        if y is None:
            y = cury
        self.realMouse.release(x, y, button)

    def move(self, deltaX, deltaY):
        curx, cury = self.realMouse.position()
        if deltaX is not None:
            curx += deltaX
        if deltaY is not None:
            cury += deltaY
        self.realMouse.move(curx, cury)

    def moveAbsolute(self, x, y):
        self.realMouse.move(x, y)
Exemplo n.º 53
0
def press_left(t=1.0) :
    m = PyMouse()

    xt=random.randint(1400, 1600)
    yt=random.randint(260, 500)

    m.position()
    m.move(xt, yt)
    time.sleep(0.2)
    m.press(xt, yt)
    time.sleep(t)
    m.release(xt, yt)
Exemplo n.º 54
0
 def test_1st_event(self):
     size = (100, 100)
     try:
         disp = Display(visible=VISIBLE, size=size).start()
         mouse = PyMouse()
         event = Event()
         event.start()
         event.pos = None
         mouse.move(10, 10)
         time.sleep(0.1)
         eq_((10, 10), event.pos)
         event.stop()                
     finally:
         disp.stop()
Exemplo n.º 55
0
 def test_event(self):
     for size in screen_sizes:
         with Display(visible=VISIBLE, size=size):
             time.sleep(3)  # TODO: how long should we wait?
             mouse = PyMouse()
             event = Event()
             event.start()
             for p in positions:
                 event.pos = None
                 mouse.move(*p)
                 time.sleep(0.1)  # TODO: how long should we wait?
                 print 'check ', expect_pos(p, size), '=', event.pos
                 eq_(expect_pos(p, size), event.pos)
             event.stop()                
Exemplo n.º 56
0
 def test_event(self):
     for size in screen_sizes:
         try:
             disp = Display(visible=VISIBLE, size=size).start()
             mouse = PyMouse()
             event = Event()
             event.start()
             for p in positions:
                 event.pos = None
                 mouse.move(*p)
                 eq_(expect_pos(p, size), event.pos)
             event.stop()                
         finally:
             disp.stop()
Exemplo n.º 57
0
    def flicker(self):
        """
        This method simply jiggles the mouse. It is used as
        part of a workaround for LoopingCall's getting stuck
        on the first call when using qt4reactor on linux.
        """
        from platform import system

        if (self.activeWindow is not None) and system() == "Linux":
            from pymouse import PyMouse

            m = PyMouse()
            x, y = m.position()
            m.move(x + 1, y)
	def showVideo(self,click_allow_arg):
		lower_IR = np.array([0,0,50]) # lower bound of CV filter
		upper_IR = np.array([255,255,255]) # upper bound of CV filter
		rawCapture = PiRGBArray(self.cam_handle, size=self.cam_res) # capture to array
		m = PyMouse() # make mouse object
		prev_maxLoc = (0,0) # init previous maxLoc
		try:
			for frame in self.cam_handle.capture_continuous(rawCapture, format = 'bgr', use_video_port=True):
				image = frame.array # get the array values for that frame
				mask = cv2.inRange(image, lower_IR, upper_IR) # mask according to lower/upper filter values
				(minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(mask) # find min/max values of image
				true_pnt = self.get_true_point(maxLoc)
				print true_pnt #DEBUG INFO PRINTOUT
				adjusted_maxx = int(((true_pnt[0]) * self.output_res[0])/(self.screen_res[0])) # take the distance from the edge and perform dimensional analysis
				adjusted_maxy = int(((true_pnt[1]) * self.output_res[1])/(self.screen_res[1])) # take the distance from the edge and perform dimensional analysis
				if click_allow_arg: # if user wants to have clicks when IR found
					if maxLoc != (0,0): # if not on the default location			
						m.press(adjusted_maxx,adjusted_maxy, 1) # press the "mouse" button at location found
					elif prev_maxLoc != (0,0) and maxLoc == (0,0): # if the current value is the default and the last value wasn't the default, release
						m.release(prev_maxLoc[0],prev_maxLoc[1], 1) # release the "mouse" button
				else: # only move the mouse, no clicking
					if maxLoc != (0,0): # if not on the default location
						m.move(adjusted_maxx,adjusted_maxy) # move the mouse
				prev_maxLoc = (adjusted_maxx,adjusted_maxy) # set previous to be current max loc
				cv2.circle(image, maxLoc, 21, (255,0,0), 2) # place circle on brightest spot
				cv2.imshow("TestWindow", cv2.resize(image,(160,120))) # show the image in a tiny window
				cv2.waitKey(1) & 0xFF # needed for preview
				rawCapture.seek(0) # return to the 0th byte
				rawCapture.truncate() # clear array for next frame
				print "Mouse at: ", m.position() #DEBUG INFO PRINTOUT
		except KeyboardInterrupt: # used to quit the function
			rawCapture.seek(0) # return to the 0th byte
			rawCapture.truncate() # clear array for next frame