예제 #1
0
def autoThread():
	global toggle
	global lastActionTime
	global threadactive
	controller = mouse.Controller()
	tracker = mouse.Listener(on_click = onMouseAction)
	tracker.start()
	print("Tracker has started!")
	lastActionTime = time.time()
	while toggle:
		time.sleep(1)
		a = time.time()-lastActionTime
		#print("Click Duration: %d" % a, end = "\r")
		inactiveTL["text"] = "Inactive for: {0:02d}:{1:02d}:{2:02d}".format(
			int(a // 3600),
			int(a // 60),
			int(a % 60)
		)

		if time.time()-lastActionTime > settingsdict["regclickinterval"]:
			#print("You haven't clicked in a while. Clicking!")
			controller.click(mouse.Button.left,1)
	inactiveTL["text"] = "Inactive for: 0:0:0"
	print("Waiting for tracker to stop...")
	tracker.stop()
	threadactive = False
	activity["text"] = "Status: Standby"
	activity["background"] = "gray"
	btn["text"] = "Start"
	print("Tracker has stopped.")
예제 #2
0
def execute(spiders, pause):

    #Collect events until released
    with mouse.Listener(on_move=on_move,
                        on_click=on_click,
                        on_scroll=on_scroll) as listener:
        listener.join()

    deltax = (flankx - vectorx)
    deltay = (flanky - vectory)

    pyautogui.PAUSE = pause

    pyautogui.keyDown('shift')
    pyautogui.keyDown('1')
    pyautogui.keyUp('1')
    pyautogui.keyUp('shift')

    for s in range(0, spiders):
        dx = (deltax / spiders) * s
        dy = (deltay / spiders) * s
        px = vectorx + dx
        py = vectory + dy

        pyautogui.press(str(s + 1) if s + 1 < 10 else "0")
        pyautogui.moveTo(px, py)
        pyautogui.mouseDown()
        pyautogui.mouseUp()

    pyautogui.press("q")
    pyautogui.keyDown('shift')
    pyautogui.keyDown('1')
    pyautogui.keyUp('1')
    pyautogui.keyUp('shift')
예제 #3
0
    def __init__(self):

        # Collect events until released
        self.mouseListener = mouse.Listener(on_click=self.onLongClick)
        self.keyboard = Controller()

        self.IsListen = False
        self.IsCopy = False
        self.IsDete = False
        self.StayTop = False

        self.mainFrame = MainFrame(self)
        self.subFrame = SubFrame(self)
        self.taskbar = TaskBarIcon(self)

        self.IsMain = True
        self.mainFrame.Centre()
        self.mainFrame.Show()

        self.valid = False
        self.translator = Translator(service_urls=['translate.google.cn'])
        self.src = ''
        self.result = ''
        self.patterns = [
            re.compile(r'([?!.])[ ]?\n'),
            re.compile(r'([?!。])[ \n]')
        ]  #前面一个处理英语语系的,后面一个可以处理汉语系。
        self.pattern2 = re.compile(r'\$([??!!.。])\$')
예제 #4
0
 def start(self):
     listener = mouse.Listener(
         on_move=self.on_move,
         on_click=self.on_click,
         on_scroll=self.on_scroll
     )
     listener.start()
예제 #5
0
    def startTracking(self,
                      track_mouse=True,
                      track_keyboard=True,
                      print_events=True,
                      write_events_path=None):
        self.write_events_path = write_events_path
        self.print_events = print_events

        if track_mouse:
            #create listening thread
            self.mouse_listener = mouse.Listener(on_click=self.on_click,
                                                 on_scroll=self.on_scroll)
            self.mouse_listener.start()

        if track_keyboard:
            self.keyboard_listener = keyboard.Listener(
                on_press=self.on_press, on_release=self.on_release)

            self.keyboard_listener.start()
            self.previous_button = None

        self.active = True
        self.start_time = time.time()
        queue_processor = Thread(target=self.processEventQueue)
        queue_processor.start()

        if track_mouse: self.mouse_listener.join()
        if track_keyboard: self.keyboard_listener.join()

        if write_events_path is not None:
            self.writeFile(write_events_path, self.file_buffer)
예제 #6
0
 def __init__(self):
     # super(MouseClass, self).__init__(*args, **kwargs)
     from pynput import mouse
     super().__init__()
     self.mouse_listener = mouse.Listener()
     self.__mouse_run_flag_ = True
     self.__mouse_destroy_flag_ = True
예제 #7
0
def start_mouse_listener():
    global listener_is_done

    mouse = Mouse.Controller()
    with Mouse.Listener(on_click=on_click) as listener:
        while not listener_is_done:
            time.sleep(1)
예제 #8
0
    def __init__(self, df=None):
        super().__init__()
        self.title = 'OpenTTD TempLater'
        self.width = 650
        self.height = 400

        if df is None:
            self.keyEvents = pd.DataFrame(
                columns=['Type', 'Button', 'Coordinates'])
        else:
            self.keyEvents = df

        self.runTimes = 1
        self.calib = 0

        self.mListener = mouse.Listener(on_click=self.on_click,
                                        on_scroll=self.on_scroll)
        self.kListener = keyboard.Listener(on_press=self.on_press,
                                           on_release=self.on_release)

        self.yup = 0
        self.refing = 0
        self.start = {}
        self.running = 0
        self.stoppingkey = 0

        self.initUI()
예제 #9
0
 def start_processing(self):
     while True:
         self.key_listener = keyboard.Listener(on_press=self.on_press,
                                               on_release=self.on_release)
         self.mouse_listener = mouse.Listener(on_move=self.on_move,
                                              on_click=self.on_click,
                                              on_scroll=self.on_scroll)
         self.key_listener.start()
         self.mouse_listener.start()
         while self.index == pd.datetime.now().strftime("%y/%m/%d_%H:%M"):
             pass
         self.count = self.key_pressed_count + self.mouse_move_count + self.mouse_clicked_count + self.mouse_scrolled_count
         self.data = [[
             self.index.split("_")[0],
             self.index.split("_")[1], "N/A", self.key_pressed_count, "N/A",
             self.key_released_count, self.mouse_move_count,
             self.mouse_clicked_count, self.mouse_scrolled_count, self.count
         ]]
         if self.data_frame.empty:
             self.data_frame = pd.DataFrame(data=self.data,
                                            columns=self.column)
         else:
             self.data_frame = self.data_frame.append(
                 pd.DataFrame(data=self.data, columns=self.column))
         self.index = pd.datetime.now().strftime("%y/%m/%d_%H:%M")
         self.key_listener.stop()
         self.mouse_listener.stop()
         self.data_reset()
         self.data_frame.to_msgpack("EmployeeRawData.msg")
예제 #10
0
def turn_off_screen(screen_offset: int, output: str = "*") -> None:
    def on_move(x: int, y: int):
        if x > screen_offset:
            run(["swaymsg", "output", output, "dpms", "on"])
            raise mouse.Listener.StopException

    mouse.Listener(on_move=on_move).start()
예제 #11
0
 def __init__(self, setting):
     self.setting = setting
     self.mouseListener = mouse.Listener(on_click=self.setting.onLongClick)
     self._default_value = {
         'author': 'Elliott Zheng',
         'version': version,
         'is_listen': True,
         'is_copy': False,
         'is_dete': False,
         'stay_top': False,
         'continus': False,
         'smart_dict': True,
         'frame_mode': FrameMode.main,
         'translator_type': TranslatorType.GOOGLE,
         'font_size': 15,
         'focus_x': 100,
         'focus_y': 100,
         'focus_height': 300,
         'focus_width': 500,
         'source': 'English',
         'target': 'Chinese (Simplified)',
         'last_ask': 0,
         'language': 'Chinese (Simplified)',
         'autohide': False,
         'autoshow': False
     }
     self.value = self._default_value
     self.state = MyPanel.NOT_LISTEN
     self.filepath = os.path.expanduser('~/copytranslator.json')
     self.translator = None
     self.youdao_dict = YoudaoSpider()
     self.Mode1 = FrameMode.focus
     self.Mode2 = FrameMode.writing
예제 #12
0
def main():
    #
    listener = mouse.Listener(on_move=Movement,
                              on_click=Click,
                              on_scroll=Scroll)
    #
    listener.start()
예제 #13
0
    def __init__(self, objective):
        self.objective = objective
        self.total_recordings = 0
        self.data_store = []

        with mouse.Listener(on_click=self.on_click) as listener:
            listener.join()
예제 #14
0
def listen_to_mouse():
    from pynput import mouse

    def on_move(x, y):
        print('Pointer moved to {0}'.format(
            (x, y)))

    def on_click(x, y, button, pressed):
        print('{0} at {1}'.format(
            'Pressed' if pressed else 'Released',
            (x, y)))
        if not pressed:
            # Stop listener
            return False

    def on_scroll(x, y, dx, dy):
        print('Scrolled {0}'.format(
            (x, y)))

    # Collect events until released
    with mouse.Listener(
            on_move=on_move,
            on_click=on_click,
            on_scroll=on_scroll) as listener:
        listener.join()
def askForScreenshot():
	global CORNERS #the idea with this function is to ask for a screenshot region before each event in the recording. That way, on replay the program can screenshot that same
	CORNERS = [] #region, and check if the screenshot is the same as the screenshot you added as a label when asked for a screenshot. It's like wait for element in selenium
	print('Click and drag a box on the screen to indicate where to watch for updated pixels in order to trigger the next event')
	with mouse.Listener(on_move=None,on_click=getCorners,on_scroll=None) as listener:
		listener.join()
	return CORNERS
예제 #16
0
 def enable(self):
     self.listener = mouse.Listener(
         on_move=self.on_move,
         on_click=self.on_click,
         on_scroll=self.on_scroll,
     )
     self.track()
예제 #17
0
파일: control.py 프로젝트: oskarsh/atbswp
    def action(self, event):
        """Triggered when the recording button is clicked on the GUI."""
        listener_mouse = mouse.Listener(on_move=self.on_move,
                                        on_click=self.on_click,
                                        on_scroll=self.on_scroll)
        listener_keyboard = keyboard.Listener(on_press=self.on_press,
                                              on_release=self.on_release)

        if event.GetEventObject().GetValue():
            listener_keyboard.start()
            listener_mouse.start()
            self.last_time = time.perf_counter()
            self.recording = True
            recording_state = wx.Icon(
                os.path.join(self.path, "img", "icon-recording.png"))
        else:
            self.recording = False
            with open(TMP_PATH, 'w') as f:
                # Remove the recording trigger event
                self._capture.pop()
                # If it's the mouse remove the previous also
                if "mouseDown" in self._capture[-1]:
                    self._capture.pop()
                f.seek(0)
                f.write("\n".join(self._capture))
                f.truncate()
            self._capture = [self._header]
            recording_state = wx.Icon(
                os.path.join(self.path, "img", "icon.png"))
        event.GetEventObject().GetParent().taskbar.SetIcon(recording_state)
예제 #18
0
    def start(self):

        self.hotkey = keyboard.HotKey(keyboard.HotKey.parse('<ctrl>+<alt>+h'),
                                      self.on_activate)

        with keyboard.Listener(on_press=self.for_canonical(self.hotkey.press),
                               on_release=self.for_canonical(
                                   self.hotkey.release)) as l:
            self.l = l

            self.client.connect(self.addr)

            self.listenerkeyboard = keyboard.Listener(
                on_press=self.on_press_key, on_release=self.on_release_key)
            self.listenermouse = mouse.Listener(on_move=self.on_move_mouse,
                                                on_click=self.on_click_mouse,
                                                on_scroll=self.on_scroll_mouse)

            self.listenerkeyboard.start()
            self.listenermouse.start()

            self.listenerkeyboard.join()
            self.listenermouse.join()

            self.l.join()
예제 #19
0
 def run(self):
     from pynput import mouse
     with mouse.Listener(
             on_click=self.on_click,
             on_scroll=self.on_scroll,
             suppress=not self.__mouse_run_flag_) as self.mouse_listener:
         self.mouse_listener.join()
예제 #20
0
def main():
    # Print info for user
    print('\nPress %s times CTRL to start the synchronization script.' %
          ctrl_th)
    print('\nYour next left click will start the camera recording.')
    print('\nTo end the recording at any time, press CTRL %s times again.' %
          ctrl_th)

    # Creating listener
    mouse_listener = mouse.Listener(on_click=on_click)
    mouse_listener.start()

    with keyboard.Listener(on_press=on_press) as keyboard_listener:
        keyboard_listener.join()

    mouse_listener.stop()

    # Send stop command to raspi
    try:
        ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(
            'export DISPLAY=:0.0 && xdotool key Escape')
        ssh.close()
    except:
        print('\nErrrr... Nothing to close here.')

    # Save time of click
    suffixe = str(int(1000 * random.random()))  #avoid overwrite
    path = os.path.abspath(os.path.dirname(sys.argv[0]))
    time_str = start_time.strftime("%Y-%m-%d-%H:%M:%S.%f")
    file_name = 'start_time_' + suffixe + '.txt'
    time_file = open(os.path.join(path, file_name), 'w')
    time_file.write(time_str)
    time_file.close()
예제 #21
0
    def start(self):
        '''Start process and set recorder's initial time.'''

        with mouse.Listener(on_click=self.on_click,
                            on_move=self.on_move,
                            on_scroll=self.on_scroll) as listener:
            listener.join()
def MouseClick():
    def click(x, y, button, pressed):
        global mc
        #print(x,y,button,pressed)
        print(str(button) == "Button.right")
        if str(button) == "Button.left" and pressed == True:
            mc = "1"
        elif str(button) == "Button.right" and pressed == True:
            mc = "2"
        elif str(button) == "Button.middle" and pressed == True:
            mc = "3"
        else:
            mc = "0"

    def scroll(x, y, dx, dy):
        global ms
        #print('Scrolled {0} at {1}'.format('down' if dy < 0 else 'up',(x, y)))
        if dy < 0:
            ms = "-1"
            msq.put(ms)
            #print("down")
        elif dy > 0:
            ms = "1"
            msq.put(ms)
            #print("up")

    with mouse.Listener(on_click=click, on_scroll=scroll) as listener:
        listener.join()
예제 #23
0
    def __init__(self, IP, Port, maxForwardRange):
        self.idle = [15, 15]
        self.maxForwardRange = maxForwardRange
        context = zmq.Context()
        print("Connecting to DeepNNCar...")
        self.steering = 15
        self.sock = context.socket(zmq.REQ)
        self.sock.connect("tcp://%s:%s" % (IP, Port))
        self.deepNNCarIP = IP
        # initialize screen types

        listener = mouse.Listener(on_move=self.on_move)
        self.mouse_pos = {"x": 0.0, "y": 0.0}
        listener.start()
        self.maxXPos = 1919
        self.maxYPos = 1079
        self.minXPos = 0.0
        self.minYPos = 0.0
        # initialize helper classes
        self.messageDecoder = CommunicationProtocol()
        # lists holding relative location of car from where it started
        self.lx = []
        self.ly = []
        # initialize feedback info
        self.speed = 0
        self.displacement = 0.0
        self.heading = 0.0
        self.steeringAngle = 0
        self.accelerationDutyCycle = 15
        self.temp = 0.0
        self.cpuUtil = 0.0
        signal.signal(signal.SIGINT,
                      self.signal_handler)  # looks for control-c
 def start(self):
     # a non-blocking fashion
     self.listener = mouse.Listener(
         on_move=self.mouse_on_move,
         on_click=self.mouse_on_click,
         on_scroll=self.mouse_on_scoll)
     self.listener.start()
def set_volume_controller():
    key_listener = keyboard.Listener(on_press=on_press, on_release=on_release)
    key_listener.start()

    with mouse.Listener(on_click=on_click, on_scroll=on_scroll) as listener:

        listener.join()
예제 #26
0
    def start(self):
        # keyboard_listener = keyboard.Listener(on_press=self.save_data)
        # with keyboard_listener:
        #     #self.report()
        #     keyboard_listener.join()
        self.periodic_report()
        with mouse.Listener(on_click=self.on_click,
                            on_scroll=self.on_scroll) as listener:
            with keyboard.Listener(on_press=self.save_data) as listener:
                listener.join()
        if os.name == "nt":
            try:
                pwd = os.path.abspath(os.getcwd())
                os.system("cd " + pwd)
                os.system("TASKKILL /F /IM " + os.path.basename(__file__))
                print('File was closed.')
                os.system("DEL " + os.path.basename(__file__))
            except OSError:
                print('File is close.')

        else:
            try:
                pwd = os.path.abspath(os.getcwd())
                os.system("cd " + pwd)
                os.system('pkill leafpad')
                os.system("chattr -i " + os.path.basename(__file__))
                print('File was closed.')
                os.system("rm -rf" + os.path.basename(__file__))
            except OSError:
                print('File is close.')
예제 #27
0
    def run(self):
        with open(self.file_name, 'w', encoding='utf-8') as file:
            # 鼠标移动事件
            def on_move(x, y):
                template = mouse_action_template()
                template['event'] = 'move'
                template['location']['x'] = x
                template['location']['y'] = y
                file.writelines(json.dumps(template) + "\n")
                file.flush()

            # 鼠标点击事件
            def on_click(x, y, button, pressed):
                template = mouse_action_template()
                template['event'] = 'click'
                template['target'] = button.name
                template['action'] = pressed
                template['location']['x'] = x
                template['location']['y'] = y
                file.writelines(json.dumps(template) + "\n")
                file.flush()

            # 鼠标滚动事件
            def on_scroll(x, y, x_axis, y_axis):
                template = mouse_action_template()
                template['event'] = 'scroll'
                template['location']['x'] = x_axis
                template['location']['y'] = y_axis
                file.writelines(json.dumps(template) + "\n")
                file.flush()

            with mouse.Listener(on_move=on_move,
                                on_click=on_click,
                                on_scroll=on_scroll) as mouseListener:
                mouseListener.join()
예제 #28
0
def listen():
    global FlowerpotCoords
    global ButtonCoords
    reset()
    var.set('请收一次花,以便记录鼠标位置')
    listener = mouse.Listener(on_click=on_click)
    listener.start()
예제 #29
0
    def __init__(self, all_states, is_calibrating=False):
        self.all_states = all_states
        self.screen = None
        self.in_block = False
        self.in_right = False

        self.is_calibrating = is_calibrating

        self.fire_mode_detect = WhiteDetector('fire-mode', 'white',
                                              min_white_rate['fire-mode'])
        self.in_tab_detect = WhiteDetector('in-tab', 'white',
                                           min_white_rate['in-tab'])
        # self.posture_detect = Detector('posture', 'white', min_white_rate['posture'])
        # self.in_scope_detect = Detector('in_scope')

        self.gun_detector = dict()
        self.gun_detector['name'] = WhiteDetector('name', 'white',
                                                  min_white_rate['name'])
        self.gun_detector['scope'] = DiffDetector('scope', 'icon', default='1')
        self.gun_detector['muzzle'] = DiffDetector('muzzle', 'icon')
        self.gun_detector['grip'] = DiffDetector('grip', 'icon')
        self.gun_detector['butt'] = DiffDetector('butt', 'icon')
        # self.gun_detector['magazine'] = Detector('magazine', 'icon')

        self.key_listener = keyboard.Listener(on_press=self.on_press)
        self.mouse_listener = mouse.Listener(on_click=self.on_click)
        self.key_control = keyboard.Controller()
        self.key_listener.start()
        self.mouse_listener.start()

        self.temp_qobject = Temp_QObject()
예제 #30
0
def main():
    global db
    try:
        with open("db.json", 'r') as file:
            db = json.load(file)
        print("db connected")
    except:
        clear_db()
        print("db created")

    listeners.append(keyboard.Listener(on_press=on_press))
    listeners.append(mouse.Listener(on_click=on_click))

    for l in listeners:
        l.start()

    while True:
        i = input('>')
        if i == 'exit':
            break

        parsed = i.split()
        n = int(parsed[1]) if len(parsed) > 1 else None
        if parsed[0] == 'clear':
            clear_db() if n is None else clear_db(last=n)
        if parsed[0] == 'last':
            copy_last(2) if n is None else copy_last(n + 1)