Example #1
0
def quick_click(x=-1, y=-1, mousebutton=1, detect_movement=True):
    if detect_movement and mouse_moved(x, y):
        raise Exception('Mouse moved!')

    if x < 0 or y < 0:
        x, y = pymouse.PyMouse().position()
    pymouse.PyMouse().click(x, y, mousebutton)

    last_mouse_pos = pymouse.PyMouse().position()
Example #2
0
def click(x=-1, y=-1, mousebutton=1, detect_movement=True):
    if detect_movement and mouse_moved(x, y):
        raise Exception('Mouse moved!')

    if x < 0 or y < 0:
        x, y = pymouse.PyMouse().position()
    pymouse.PyMouse().press(x, y, mousebutton)
    time.sleep(0.5)
    pymouse.PyMouse().release(x, y, mousebutton)
    time.sleep(1)
Example #3
0
 def __init__(self, num_parking_spots):
     PyMouseEvent.__init__(self)
     self.point_ctr = 0
     self.line_ctr = 0
     self.num_parking_spots = num_parking_spots
     self.mouse = pymouse.PyMouse()
     sys.stdout.write(str(self.line_ctr))
Example #4
0
    def run(self):
        self.running_monitor_thread = True
        try:
            mouse = pymouse.PyMouse()
            while self.running_monitor_thread:
                if self.powersave and not self.working_hours():
                    self.sleep_with_one_eye_open(SECONDS_BETWEEN_POLLS)
                    continue

                if self.keep_alive:
                    (initial_x, initial_y) = mouse.position()
                    new_x = initial_x + MOUSE_DIFF
                    new_y = initial_y + MOUSE_DIFF
                    mouse.move(new_x, new_y)

                (success, unstable, fail, _,
                 _) = self.jenkins.get_build_status()
                self.post_jenkins_status(monitor_view.UPDATE_BUILD_PUBSUB,
                                         success, unstable, fail)
                if not self.running_monitor_thread:
                    break

                (success, unstable, fail, _,
                 _) = self.jenkins.get_ci_test_status()
                self.post_jenkins_status(monitor_view.UPDATE_CI_TEST_PUBSUB,
                                         success, unstable, fail)
                if not self.running_monitor_thread:
                    break

                (success, unstable, fail, _,
                 _) = self.jenkins.get_other_tests_status()
                self.post_jenkins_status(
                    monitor_view.UPDATE_OTHER_TESTS_PUBSUB, success, unstable,
                    fail)
                if not self.running_monitor_thread:
                    break

                (gerrit_for_review,
                 gerrit_reviewed) = self.gerrit.all_open_changes()

                rfr_status = len(gerrit_for_review)
                self.post_ready_for_review_status(rfr_status)
                reviewed_status = len(gerrit_reviewed)
                self.post_reviewed_status(reviewed_status)

                # Move mouse back a little
                if self.keep_alive:
                    (initial_x, initial_y) = mouse.position()
                    new_x = initial_x - MOUSE_DIFF
                    new_y = initial_y - MOUSE_DIFF
                    mouse.move(new_x, new_y)

                self.sleep_with_one_eye_open(SECONDS_BETWEEN_POLLS)

        except Exception as e:
            logging.error('monitor thread exception:\n%s', str(e))
            time.sleep(1)  # Just to give the view time to subscribe
            Publisher.sendMessage(monitor_view.SHUTDOWN_PUBSUB)

        logging.debug('done monitoring')
Example #5
0
def talker():
    pub = rospy.Publisher("mouse_speeds", TwistStamped, queue_size=10)
    rospy.init_node('mouse_talker')
    rate = rospy.Rate(100)
    m = pymouse.PyMouse()
    pos = []
    pos_ = []
    _pos = []
    i = 0
    while not rospy.is_shutdown():
        pos_ = m.position()
        if i >= 2:
            _vx = (pos[0] - _pos[0]) / 0.01
            _vy = (pos[1] - _pos[1]) / 0.01
            vx_ = (pos_[0] - pos[0]) / 0.01
            vy_ = (pos_[1] - pos[1]) / 0.01
            vx = (vx_ + _vx) / 2000
            vy = (vy_ + _vy) / 2000
            info_str = "x: " + pos[0].__str__() + " y: " + pos[1].__str__(
            ) + " vx: " + vx.__str__() + " vy: " + vy.__str__()
            rospy.loginfo(info_str)
            mouse_msg = TwistStamped()
            mouse_msg.twist.linear.x = pos[0] / 1000.0
            mouse_msg.twist.linear.y = pos[1] / 1000.0
            mouse_msg.twist.angular.x = vx
            mouse_msg.twist.angular.y = vy
            pub.publish(mouse_msg)
        _pos = pos
        pos = pos_
        i = i + 1
        rate.sleep()
Example #6
0
def screensize():
    m = pymouse.PyMouse()
    size = m.screen_size()
    size = np.asarray(size)
    size[0] = size[0] * 0.5
    size[1] = size[0] * 0.5
    return size
Example #7
0
    def grab_region_point(self, count, first):
        mouse_pos = None

        if count > 0:
            m = pymouse.PyMouse()
            if first:
                txt = "Move your mouse to the top left corner of your region. (" + str(count) + " seconds remaining)"
            else:
                txt = "Move your mouse to the lower right corner of your region. (" + str(count) + " seconds remaining)"
            
            print txt
            self.inputsrcinfo.setText(txt)

            time.sleep(1)
            count -= 1
            mouse_pos = m.position()

            self.grab_region_point(count, first)
        else:
            if first:
                txt = "Top left coordinate saved. Moving to bottom right coordinate..."
            else:
                txt = "Bottom right coordinate saved."

            print txt
            self.inputsrcinfo.setText(txt)

            time.sleep(1)

        return mouse_pos
Example #8
0
    def __init__(self):
        super(ClickKeyEventListener, self).__init__(True)
        self.mouse = pymouse.PyMouse()
        self._mouse_down = False
        self._mouse_down_lock = threading.Lock()

        self._enable = True
        self._enable_lock = threading.Lock()
Example #9
0
    def __init__(self, **kwargs):
        Surface.__init__(self, **kwargs)
        screen_resolution = kwargs.get('screen_resolution', None)
        fullscreen = kwargs.get('fullscreen', False)
        fps = kwargs.get('fps', None)
        center = kwargs.get('center', True)

        args = get_args()
        if screen_resolution is None:
            pm = pymouse.PyMouse()
            screen_resolution = pm.screen_size()
            if args.debug:
                print("selected resolution: " + str(screen_resolution))
        ffmpeg = "ffmpeg"
        display = os.getenv("DISPLAY")
        if fps == None:
            fps = get_args().fps
        if fullscreen:
            fmt = screen_resolution
            fmtstr = "%dx%d"
            screensize = fmtstr % fmt
            scale = "scale=%d:%d" % (self.width, self.height)
            command = [ffmpeg,
                       '-loglevel', 'panic',
                       '-video_size', screensize,
                       '-r', '30',
                       '-f', 'x11grab',
                       '-i', display,
                       '-f', 'image2pipe',
                       '-pix_fmt', 'rgb24',
                       '-vcodec', 'rawvideo',
                       '-preset', 'ultrafast',
                       '-crf', '0',
                       '-vf', scale,
                       '-an', '-']
        else:
            fmt = (self.width, self.height)
            fmtstr = "%dx%d"
            screensize = fmtstr % fmt
            command = [ffmpeg,
                       '-loglevel', 'panic',
                       '-video_size', screensize,
                       '-r', '30',
                       '-follow_mouse', 'centered',
                       '-draw_mouse', '0',
                       '-f', 'x11grab',
                       '-i', display,
                       '-f', 'image2pipe',
                       '-pix_fmt', 'rgb24',
                       '-vcodec', 'rawvideo',
                       '-preset', 'ultrafast',
                       '-crf', '0',
                       '-an', '-']

        command = ' '.join(command)
        if args.debug:
            print("\ncommand: %s" % (command))
        self.pipe = sp.Popen(shlex.split(command), stdout=sp.PIPE)
Example #10
0
 def MouseOnPopUp(self):
     m = pymouse.PyMouse()
     mouse_pos = m.position()
     if mouse_pos[0] > self.position[0] + 5 and mouse_pos[0] < (
             self.position[0] + self.GetSize()[0] - 5):
         if mouse_pos[1] > self.position[1] + 5 and mouse_pos[1] < (
                 self.position[1] + self.GetSize()[1] - 5):
             return True
     return False
Example #11
0
 def __init__(self, vbox_mode):
     self.logger = logging.getLogger('mouse')
     self.logger.setLevel(logging.DEBUG)
     if vbox_mode:
         super().__init__()
     self.mouse = pymouse.PyMouse()
     self.vbox_mode = vbox_mode
     self.old_x = int(np.round(np.random.uniform(0, 500, 1)))
     self.old_y = int(np.round(np.random.uniform(0, 500, 1)))
Example #12
0
 def open(self):
     ImageWebSocket.clients.add(self)
     print("WebSocket opened from: " + self.request.remote_ip)
     # camera.request_start()
     global sct
     if not bool(sct):
         sct = mss.mss()
     global mouse
     if not bool(mouse):
         mouse = pymouse.PyMouse()
Example #13
0
 def __init__(self):
     super(TestScreenCap, self).__init__()
     self.operator = 0
     # screenshot
     self.screen = None
     self.train = TrainSVM()
     # self.train.train()
     self.grab = GrabScreen()
     # mouse click
     self.mouse = pymouse.PyMouse()
def getTarget():
    p = pymouse.PyMouse().position()
    sizex = 200
    sizey = 200
    areaOfEffect = [p[0] - sizex, p[1] - sizey, p[0] + sizex, p[1] + sizey]
    #areaOfEffect= [1041,231,1822,502] # based on canvas
    im = pyscreenshot.grab(areaOfEffect)
    im = np.array(im)
    im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
    return im, areaOfEffect
Example #15
0
    def OnElementRightClick(self, event):
        element_num = event.id

        m_pos= pymouse.PyMouse().position()
        if self.popWin: 
            self.popWin.Show(False)
            self.popWin.Destroy()
        self.popWin = ElementOptions(self.GetTopLevelParent(), self.collection_id, element_num, m_pos)

        self.popWin.Show(True)
Example #16
0
def resize_state(sm_model, sm_notebook_page, graphical_editor_controller):
    # Important: do not remove any information (including comments) of this function! Needed for debugging!
    import pymouse
    mouse = pymouse.PyMouse()
    from gaphas.item import Element, NW, NE, SE, SW

    from rafcon.gui.controllers.graphical_editor_gaphas import GraphicalEditorController
    assert isinstance(graphical_editor_controller, GraphicalEditorController)
    state_view_for_root_state = graphical_editor_controller.canvas.get_view_for_model(
        sm_model.root_state)
    from rafcon.gui.mygaphas.items.state import StateView
    assert isinstance(state_view_for_root_state, StateView)
    # print state_view_for_root_state
    # p = state_view_for_root_state.position
    # print state_view_for_root_state.position
    # print state_view_for_root_state.matrix
    # print state_view_for_root_state.handles()
    # print state_view_for_root_state.handles()[NW].pos.x
    # print state_view_for_root_state.handles()[NW].pos.y
    # print state_view_for_root_state.handles()[SE].pos.x
    # print state_view_for_root_state.handles()[SE].pos.y

    # self.view.get_matrix_i2v(self).transform_distance(width, height)
    from gaphas.view import View
    assert isinstance(state_view_for_root_state.view, View)

    v2i = state_view_for_root_state.view.get_matrix_v2i(
        state_view_for_root_state)
    i2v = state_view_for_root_state.view.get_matrix_i2v(
        state_view_for_root_state)
    c2i = state_view_for_root_state.canvas.get_matrix_c2i(
        state_view_for_root_state)
    i2c = state_view_for_root_state.canvas.get_matrix_i2c(
        state_view_for_root_state)

    # item_base_x, item_base_y = v2i.transform_point(p[0], p[1])
    # item_base_x, item_base_y = i2v.transform_point(p[0], p[1])
    #
    # item_base_x, item_base_y = i2c.tranform_point(v2i.transform_point(0, 0))
    # item_base_x, item_base_y = 0, 0

    se_x, se_y = i2v.transform_point(
        state_view_for_root_state.handles()[SE].pos.x.value,
        state_view_for_root_state.handles()[SE].pos.y.value)

    main_w = rafcon.gui.singleton.main_window_controller.view.get_parent_widget(
    )
    pos_main = main_w.get_position()
    rel_pos = sm_notebook_page.translate_coordinates(main_w, 0, 0)
    abs_pos_se = (pos_main[0] + rel_pos[0] + se_x,
                  pos_main[1] + rel_pos[1] + se_y)

    mouse.move(*abs_pos_se)
    mouse.press(*abs_pos_se)
    mouse.release(abs_pos_se[0] + 20, abs_pos_se[1] + 20)
Example #17
0
 def close_popups(popups):
     for popup in popups:
         elem_popup = []
         win32gui.EnumChildWindows(popup, _MyCallback, elem_popup)
         close = [window for window in elem_popup if win32gui.GetWindowText(window) == "Close the program"]
         try:
             rect = win32gui.GetWindowRect(close[0])
             pymouse.PyMouse().click(rect[0] + 10, rect[1] + 10)
         except:
             win32gui.CloseWindow(popup)
         time.sleep(2)
Example #18
0
    def __init__(self, interpreter):
        super().__init__(interpreter)

        self.__pymouse = pymouse.PyMouse()
        self.__mouse_click_event = MouseClickEvent(self)

        self._left_down = False
        self._right_down = False

        # noinspection PyProtectedMember
        threading._start_new_thread(self.__mouse_click_event.run, tuple())
 def __init__(self):
     self.touch = open('/dev/input/event5', 'r')
     self.side = open('/dev/input/event4', 'r')
     self.mouse = pymouse.PyMouse()
     self.x, self.y = self.mouse.position()
     self.width, self.height = (480, 800)
     self.finger = False
     self.landscape = True
     self.abort = False
     self.power = True
     self.backlight = 10
Example #20
0
def mouse_moved(x, y):
    global last_mouse_pos
    old_x, old_y = pymouse.PyMouse().position()
    last_x, last_y = last_mouse_pos

    if last_x > -1 and last_y > -1:
        if distance((last_x, last_y), (old_x, old_y)) > 4:
            # print(last_x, last_y, old_x, old_y, x, y)
            return True

    return False
def shoot(im, areaOfEffect):
    for i in range(1, 3):
        enemy = cv2.imread("enemy%d.png" % i, 0)
        w, h = enemy.shape[::-1]
        res = cv2.matchTemplate(im, enemy, cv2.TM_CCOEFF_NORMED)
        threshhold = 0.6
        loc = np.where(res >= threshhold)
        for pt in zip(*loc[::-1]):
            hitX = areaOfEffect[0] + pt[0]
            hitY = areaOfEffect[1] + pt[1]
            pymouse.PyMouse().click(hitX + 5, hitY + 5)
Example #22
0
    def OnNotebookRightClick(self, event):
        page_right_clicked = self.notebook.HitTest(event.GetPosition())[0]

        m_pos = pymouse.PyMouse().position()
        if self.popWin:
            self.popWin.Show(False)
            self.popWin.Destroy()
        self.popWin = ProductOptions(
            self.GetTopLevelParent(), m_pos,
            self.productPages[page_right_clicked].product_id)

        self.popWin.Show(True)
Example #23
0
def getGongHai(driver):
    # !!!!!!!!!!平台(7W+)
    driver.get('https://oa.globalso.com/high_seas/platform')
    m = pymouse.PyMouse()
    jj=0
    for i in range(1, 473):
        if i>100:
            jj=20
        main_handle = driver.current_window_handle
        time.sleep(1)
        for k in range(1, 14):
            m.click(1900, 964)
        for kk in range(1, 30):
            m.click(1900, 975)
        # 开始
        inframe = driver.find_element_by_class_name('iframe-box')
        driver.switch_to.frame(inframe)

        html = driver.page_source
        soup = BeautifulSoup(html, 'lxml')

        trs = soup.find_all('tr', {'class': 'data-item'})
        tds = soup.find_all('td', {'colspan': '11'})  # ---------------------------------------------------------------->平台

        data_list = []
        for j in range(len(trs)):
            try:
                for line in trs[j].children:
                    try:
                        data_list.append(line.string)
                    except:
                        print('第{}页,第{}个数据格式错误'.format(i, j))
                for line in tds[j].children:
                    try:
                        data_list.append(line.string)
                    except:
                        print('第{}页,第{}个数据格式错误'.format(i, j))
                try:
                    with open('2allData2.csv', 'a', newline="") as filecsv:
                        caswriter = csv.writer(filecsv)
                        caswriter.writerow(data_list)
                except:
                    print("{}{}".format(i,j))
                data_list = []
            except:
                print(i,'i')
        driver.switch_to.window(main_handle)
        driver.maximize_window()
        m.click(int(1142 + int(int(i) * 0.1)+int(jj)), 891)
        time.sleep(1)
Example #24
0
    def __init__(self, devs):
        self.mouse = pymouse.PyMouse()
        self.detect = DectKey("", "", "", "", "", "", "", "", "", "", "")
        self.devices = devs
        self.pause_keys = []
        self.rounds = 0
        self.points = []
        # Variable params
        self.start_count = {}
        self.last_start_count = {}
        self.stop_count = {}
        self.last_stop_count = {}
        self.pc_ext_count = {}
        self.last_pc_ext_count = {}
        self.udp_ext_count = {}
        self.last_udp_ext_count = {}
        self.client_ext_count = {}
        self.last_client_ext_count = {}
        for dev in self.devices:
            self.start_count[dev] = [0, 0, 0, 0]
            self.last_start_count[dev] = [0, 0, 0, 0]
            self.stop_count[dev] = [0, 0, 0, 0]
            self.last_stop_count[dev] = [0, 0, 0, 0]
            self.pc_ext_count[dev] = []
            self.last_pc_ext_count[dev] = []
            self.udp_ext_count[dev] = []
            self.last_udp_ext_count[dev] = []
            self.client_ext_count[dev] = []
            self.last_client_ext_count[dev] = []

        # Table
        self.table = prettytable.PrettyTable([
            "Remote", "PC Start", "PC Stop", "UDP Start", "UDP Stop",
            "UDP CvtStart", "UDP CvtStop", "Client Start", "Client Stop",
            "Start", "Stop"
        ])
        self.table.align["Remote"] = 1
        self.table.padding_width = 1
        self.pc_ext_table = prettytable.PrettyTable(["Remote", "PC Ext"])
        self.pc_ext_table.align["Remote"] = 1
        self.pc_ext_table.padding_width = 1
        self.udp_ext_table = prettytable.PrettyTable(["Remote", "UDP Ext"])
        self.udp_ext_table.align["Remote"] = 1
        self.udp_ext_table.padding_width = 1
        self.client_ext_table = prettytable.PrettyTable(
            ["Remote", "Client Ext"])
        self.client_ext_table.align["Remote"] = 1
        self.client_ext_table.padding_width = 1
 def __init__(self):
     self.bottomRowStacks = [[], [], [], [], [], [], []]
     self.moveCount = 0
     self.lastMove = ((-1, -1), (-1, -1))  # dummy values
     self.m = pymouse.PyMouse()
     self.insideDist = 20
     # Solitaire Locations
     #topRow = [(875, 150), (1133, 150), (1391, 150), (1649, 150)]
     self.wastePile = (101, 151)
     #wasteCard = (359, 150)
     self.bottomRowY = 495  #the top of the bottom row
     self.bottomRowX = [101, 359, 617, 875, 1133, 1391, 1649]
     self.cardsToNotMove = []
     self.tmpCardsToNotMove = []
     self.lastWasteCard = None
     self.bottomRowInfo = None
     self.usedKings = []
def talker():
    pub = rospy.Publisher("mouse_speeds", TwistStamped, queue_size=10)
    rospy.init_node("mouse_talker")
    rate = rospy.Rate(100)
    m = pymouse.PyMouse()
    pos = [0.0, 0.0]
    pos_ = []
    c_vx = []
    c_vy = []

    index = 0
    num = 10

    for ii in range(num):
        c_vx.append(0.0)
        c_vy.append(0.0)
    while not rospy.is_shutdown():
        pos_ = m.position()
        vx = (pos_[0] - pos[0]) / 0.01
        vy = (pos_[1] - pos[1]) / 0.01
        pos = pos_
        c_vx[index] = vx
        c_vy[index] = vy
        mouse_msg = TwistStamped()
        mouse_msg.twist.linear.x = pos[0] / 2000.0 - 0.9595 / 2
        mouse_msg.twist.linear.y = pos[1] / 2000.0 - 0.5395 / 2
        sum1 = 0
        sum2 = 0
        for iii in range(num):
            sum1 = sum1 + c_vx[iii]
            sum2 = sum2 + c_vy[iii]
        mouse_msg.twist.angular.x = sum1 / (1000 * num)
        mouse_msg.twist.angular.y = sum2 / (1000 * num)
        info_str = "x: " + mouse_msg.twist.linear.x.__str__(
        ) + " y: " + mouse_msg.twist.linear.y.__str__(
        ) + " vx: " + mouse_msg.twist.angular.x.__str__(
        ) + " vy: " + mouse_msg.twist.angular.y.__str__()
        rospy.loginfo(info_str)
        pub.publish(mouse_msg)
        index = index + 1
        if index == num:
            index = 0
        rate.sleep()
Example #27
0
def main():
    parser = argparse.ArgumentParser(
        description="Make sure screen stays undimmed by moving mouse")
    parser.add_argument('-t',
                        "--time",
                        type=float,
                        default=10.0,
                        help="Enter the time in seconds(default 10s)")
    args = vars(parser.parse_args())

    t = args['time']
    stop = False
    while not stop:
        mouse = pymouse.PyMouse()
        (x, y) = mouse.position()
        mouse.move(x, y)
        print(f"Sleeping for {t} secs", end='\r', flush=True)
        time.sleep(t)

        rand = random.randint(-2, 2)
        mouse.move(x + rand, y + rand)
Example #28
0
def select_window():
    mouse = pymouse.PyMouse()
    print("Selecting frame...")
    input(
        "Place the cursor on the upper left corner. Press Enter to continue..."
    )
    x1, y1 = mouse.position()

    input(
        "Place the cursor on the lower right corner. Press Enter to continue..."
    )
    x2, y2 = mouse.position()

    if x2 < x1 or y2 < y1:
        print("\nThe input is incorrect. Try again.\n\n")
        return select_window()

    # Set window offset in context
    global context
    context.x_offset = x1
    context.y_offset = y1

    return x1, y1, x2, y2
Example #29
0
def StartCopy():
    import sys
    keyboard = Controller()
    with keyboard.pressed(Key.ctrl):
        keyboard.press('c')
        keyboard.release('c')

    app = QtGui.QApplication(sys.argv)
    window = DictionBox()
    mouse = pymouse.PyMouse()
    x, y = mouse.position()
    if x - 130 >= 0:
        x = x - 139

    y = y + 20

    window.move(x, y)
    window.show()
    app.quit()
    app.exec_()
    while True:
        keylistener = KeyListener()
        keylistener.addKeyListener("L_CTRL+m", StartCopy)
        handle = Handler(keylistener)
Example #30
0
 def __init__(self, vbox_mode):
     if vbox_mode:
         super().__init__()
     self.mouse=pymouse.PyMouse()
     self.vbox_mode=vbox_mode