Esempio n. 1
0
def record_mouse(duration=5, filename='vpt-mouse.json'):
    '''Records all mouse events and saves them to a JSON file.
       Note that it currently blocks the main thread for the given duration.'''
    events = []

    def callback(event):
        if isinstance(event, mouse.ButtonEvent):
            events.append({
                'type': 'button',
                'button': event.button,
                'action': event.event_type,
                'time': event.time,
            })
        elif isinstance(event, mouse.WheelEvent):
            events.append({
                'type': 'wheel',
                'delta': event.delta,
                'time': event.time,
            })
        elif isinstance(event, mouse.MoveEvent):
            events.append({
                'type': 'move',
                'position': {
                    'x': event.x,
                    'y': event.y,
                },
                'time': event.time,
            })

    mouse.hook(callback)
    time.sleep(duration)
    mouse.unhook(callback)
    with open(filename, 'w') as file:
        json.dump(events, file, indent=4)
Esempio n. 2
0
def start():
    print("Press 'q' to begin")
    while True:
        if keyboard.is_pressed('q'):
            mouse.hook(OnMouseEvent)
            keyboard.hook(OnKeyboardEvent)
            break
Esempio n. 3
0
def record_Shortcut(name):
    #create empty lists for the sequences of mouse and keyboard inputs
    mouse_events = []
    keyboard_events = []
    #waits for special keypress before starting the recording
    print("Press the '*' key when you would like to start recording")
    keyboard.wait('*')
    mouse.hook(mouse_events.append)

    #waits until the same keypress to stop recording
    keyboard_events = keyboard.record(until='*')
    mouse.unhook(mouse_events.append)

    print("Recording done!")

    #print statements for testing you can remove these
    #-----------------------------------------------
    print(str(mouse_events))
    print(str(keyboard_events))
    #-----------------------------------------------
    
    #takes sequence of key and mouse presses as well as the shortcut name and stores in respective files
    nfile = open("name_shortcuts.txt",'a+')
    nfile.write("%s\n" % (name))
    nfile.close()

    mfile = open("mouse_shortcuts.txt",'ab+')
    dump(mouse_events,mfile)
    mfile.close()

    kfile = open("keyboard_shortcuts.txt",'ab+')
    dump(keyboard_events,kfile)
    kfile.close()
Esempio n. 4
0
    def hook(self):
        mouse.hook(self.mouse_events.append)

        def _keyboard_hook(event):
            self.keyboard_events.append(event)

        keyboard.hook(_keyboard_hook)
Esempio n. 5
0
    def mouseStream(self, request, context):
        l = IterQueue(maxsize=30000)
        mouse.hook(l.put)
        while True:
            event = l.get()
            print(event)
            if isinstance(event, mouse._mouse_event.MoveEvent):
                x = event.x
                y = event.y
                t = event.time
                event = mouse_pb2.EventDetails(event_type='MOVE',
                                               x=x,
                                               y=y,
                                               time=t)
                yield event

            if isinstance(event, mouse._mouse_event.ButtonEvent):
                type = event.event_type
                button = event.button
                t = event.time
                event = mouse_pb2.EventDetails(event_type='BUTTON',
                                               btype=type,
                                               button=button,
                                               time=t)
                yield event

            if isinstance(event, mouse._mouse_event.WheelEvent):
                delta = event.delta
                t = event.time
                event = mouse_pb2.EventDetails(event_type='WHEEL',
                                               delta=delta,
                                               time=t)
                yield event
Esempio n. 6
0
    def mouseStream(self, request, context):
        l = IterQueue(maxsize=300)
        mouse.hook(l.put)
        print('MOUSE: OOO ----------------', end='')

        while True:
            global on_hold
            animation(on_hold)
            event = l.get()
            # print('.', end='', flush=True)

            if isinstance(event, mouse._mouse_event.MoveEvent):
                x = event.x
                y = event.y
                t = event.time
                event_to_send = mouse_pb2.EventDetails(event_type='MOVE', x=x, y=y, time=t, on_hold=on_hold)
                yield event_to_send

            if isinstance(event, mouse._mouse_event.ButtonEvent):
                type = event.event_type
                button = event.button
                t = event.time
                event_to_send = mouse_pb2.EventDetails(event_type='BUTTON', btype=type, button=button, time=t, on_hold=on_hold)
                yield event_to_send

            if isinstance(event, mouse._mouse_event.WheelEvent):
                delta = event.delta
                t = event.time
                event_to_send = mouse_pb2.EventDetails(event_type='WHEEL', delta=delta, time=t, on_hold=on_hold)
                yield event_to_send
Esempio n. 7
0
 def test_hook(self):
     events = []
     self.press()
     mouse.hook(events.append)
     self.press()
     mouse.unhook(events.append)
     self.press()
     self.assertEqual(len(events), 1)
Esempio n. 8
0
def run(inq, outq):
    mouse.hook(lambda e: event_triggered(outq, e))

    stop = False
    while not stop:
        time.sleep(1)
        if inq.get() == "stop":
            stop = True
Esempio n. 9
0
 def _record(self):
     controller = self.name.lower()
     if controller in ["mouse", "fare"]:
         mouse.hook(self.add_event)
     elif controller in ["keyboard", "klavye"]:
         keyboard.hook(self.add_event)
     else:
         raise ValueError(
             f"Hatalı değer: {controller} 'mouse' veya 'keyboard' olmalı")
Esempio n. 10
0
def zaWarudo():
    #x1, y1 = win32api.GetCursorPos()
    recorded = []
    mouse.hook(recorded.append)
    time.sleep(3)
    mouse.unhook(recorded.append)
    #print(recorded)
    print("not funny, didnt happen")
    mouse.play(reverseMouseEvent(recorded))
Esempio n. 11
0
def record_loop(dictionary):
    i = 1
    while True:
        i += 1
        keyboard.wait('insert')
        l = []
        print('recording')
        mouse.hook(l.append)
        keyboard.wait('print screen')
        mouse.unhook(l.append)
        dictionary.update({'{}'.format(str(i)), l})
Esempio n. 12
0
def run(inq, outq):
    mouse.hook(_mouse_callback(outq))
    for k in Key:
        if k not in mouse_buttons:
            keyboard.add_hotkey(k.value, _keyboard_callback(outq, k))

    stop = False
    while not stop:
        if inq.get() == "stop":
            stop = True
        time.sleep(1)
Esempio n. 13
0
def record_both(button='esc'):
    print("recording")
    keyboard_record = []
    mouse_record = []
    keyboard.hook(keyboard_record.append)
    mouse.hook(mouse_record.append)
    keyboard.wait('esc')
    keyboard.unhook(keyboard_record.append)
    mouse.unhook(mouse_record.append)
    print("done!")
    return keyboard_record, mouse_record
Esempio n. 14
0
    def run(self):
        #logging.info(str('start'))
        os.chdir(os.path.expanduser("~/Desktop"))
        if not os.path.exists("WORK_TIME"):
            os.mkdir("WORK_TIME")
        os.chdir("./WORK_TIME")

        mouse.hook(self.TimeCheck)
        keyboard.hook(self.TimeCheck)

        win32gui.PumpMessages()
Esempio n. 15
0
def main():
    # Print out a List of the Globals to Check Inits.
    DebugPrint('Printing Globals List:')
    DebugPrintGlobals()

    #Hook Logical Mouse Events.
    DebugPrint('Hooking Mouse Input')
    mouse.hook(Mouse_Input)

    #Hook Logical Keyboard Events.
    DebugPrint('Hooking Keyboard Input')
    keyboard.hook(Keyboard_Input)
Esempio n. 16
0
def record_loop_json(file):
    i = 1
    while True:
        i += 1
        keyboard.wait('insert')
        l = []
        print('recording')
        mouse.hook(l.append)
        keyboard.wait('print screen')
        mouse.unhook(l.append)
        with open(file, 'a+', encoding='utf/8') as f:
            json.dump(l)
Esempio n. 17
0
    def start_mouse_tracker(self, primary_position=(100, 100), x_channel=False, y_channel=False):
        # TODO: [REFACTOR]
        # Move mouse to primary position ie. position to be stuck in
        # Programmer.start_mouse_tracker(x_channel=1, y_channel=2)
        if x_channel is False and y_channel is False: return
        x0, y0 = primary_position
        mouse.move(x0, y0)
        # TODO: CLEAN

        def handle_mouse(evt, x0=x0, y0=y0):
            # Cancel tracking if click
            x_value = DMXSender.raw_state.get(x_channel, 0)
            y_value = DMXSender.raw_state.get(y_channel, 0)
            if isinstance(evt, mouse._mouse_event.ButtonEvent):
                mouse.unhook(handle_mouse)
            new_x, new_y = mouse.get_position()
            direction = 'none'
            shortcut_return = False
            if not keyboard.is_pressed(42):  # if not shift key
                if new_x > x0:
                    x_value = self.clamp(x_value + 5)
                    direction = 'right'
                elif new_x < x0:
                    x_value = self.clamp(x_value - 5)
                    direction = 'left'
                else:
                    shortcut_return = True
            if not keyboard.is_pressed(29):  # if not ctrl key
                if new_y > y0:
                    y_value = self.clamp(y_value - 5)
                    direction = 'down'
                elif new_y < y0:
                    y_value = self.clamp(y_value + 5)
                    direction = 'up'
                elif shortcut_return:
                    return
            if VERBOSE:
                print(
                    f'handle_mouse [+]: mouse moved {direction} {new_x=} {x_value=} {new_y=} {y_value=}')
            mouse.move(x0, y0)
            fade_arguments = []
            print(f'{x_channel=}, {y_channel=}, {x_value=}, {y_value=}')
            if x_channel is not False:
                fade_arguments.append([x_channel, x_value, 0, 'linear'])
            if y_channel is not False:
                fade_arguments.append([y_channel, y_value, 0, 'linear'])
            DMXSender.fade_instant(*fade_arguments)
            # DMXSender.fade(*fade_arguments)
            # mouse.unhook(handle_mouse)
            # eel.update_node(node, (x_value, y_value))
            return x_value, y_value
        mouse.hook(handle_mouse)
        return
Esempio n. 18
0
def listen_thread():
    global lock_flag
    global monitor_flag
    global lock_hotkey
    global windows
    while True:
        time.sleep(1)
        if (lock_flag == 1) and (monitor_flag == 0):
            print('Entering lock mode')
            monitor_flag = 1
            keyboard.hook(monitor_keyevents, suppress=True)
            mouse.hook(monitor_mouse)
            wnd_dim = []
            count = 0
            for awnd_num, awnd in enumerate(get_hwnds()):
                print(
                    win32gui.GetWindowText(awnd)[0:10], awnd,
                    win32gui.GetWindowRect(awnd))  # Print window name
                (w_l, w_t, w_r, w_b) = win32gui.GetWindowRect(
                    awnd)  # get active window placement
                wnd_dim.append((w_l, w_t, w_r, w_b))
                os.system(str(awnd_num + 1) + '.jpg')  # open picture
                # time.sleep(1)  # delay to allow picture to enter foreground
                # nwnd = win32gui.GetForegroundWindow()  # change window handle to foreground window
                # win32gui.MoveWindow(nwnd, w_l, w_t, w_r - w_l, w_b - w_t, 0)  # place window handle
            time.sleep(1)
            for nwnd in get_hwnds():
                if win32gui.GetWindowText(nwnd)[0:10] == 'Photos':
                    wnd_l = wnd_dim[count][0]
                    wnd_t = wnd_dim[count][1]
                    wnd_r = wnd_dim[count][2]
                    wnd_b = wnd_dim[count][3]
                    print(
                        win32gui.GetWindowText(nwnd)[0:10], wnd_l, wnd_t,
                        wnd_r, wnd_b)
                    win32gui.MoveWindow(nwnd, wnd_l, wnd_t, wnd_r - wnd_l,
                                        wnd_b - wnd_t,
                                        0)  # place window handle
                    count += 1
        if (lock_flag == 0) and (monitor_flag == 1):
            print('Entering unlock mode')
            monitor_flag = 0
            if windows == 1:
                subprocess.call('taskkill /im Microsoft.Photos.exe /f')
            else:
                subprocess.call('taskkill /im dllhost.exe /f')
            keyboard.unhook_all()
            keyboard.add_hotkey(lock_hotkey, lock, args=[1], suppress=True)
            mouse.unhook_all()
        if lock_flag == 1:
            search_task()
Esempio n. 19
0
def record_input():
    global play_layer
    recorded = []
    mouse.hook(recorded.append)
    # TODO: add keyboard
    while True:
        if play_layer.get_percent() == 0.0:
            play_layer = game_manager.get_play_layer()
        if play_layer.percent >= 100 or play_layer.dead:
            mouse.unhook(recorded.append)
            newrecorded = []
            for r in recorded:
                if isinstance(r, mouse.ButtonEvent) and r.button == "left":
                    newrecorded.append(r)
            return newrecorded
Esempio n. 20
0
 def run(self) -> None:
     """
     Method to init the Input Listener class thread.
     """
     self.control_thread = self._args[0]
     self.farmer_thread = self.control_thread.farmer_thread
     self.cli_thread = self.control_thread.cli_thread
     self.prowatch_thread = self.control_thread.prowatch_thread
     self.radon_thread = self.control_thread.radon_thread
     if self.farmer_thread.pause:
         self.cli_thread.input_string_mode = "paused"
     else:
         self.cli_thread.input_string_mode = "running"
     keyboard.hook(self.analyse_key_press)
     mouse.hook(self.analyse_mouse_interaction)
Esempio n. 21
0
def main():
    mouse._os_mouse.listen = listen
    print("Starting hooking")
    print(f"侧键1: {1/SPEED1:.2f}Hz, 侧键2:  {1/SPEED2:.2f}Hz")
    mouse.hook(callback)

    while 1:
        if clicked:
            print("开始点击")
            while 1:
                click()
                if not clicked:
                    break
                time.sleep(click_time)
            print("停止点击")
Esempio n. 22
0
def record(start='Ctrl + F3'):
    macro = Macro()
    try:
        print('Waiting for %s to start...' % start)
        keyboard.wait(start)
        print('Start recording. ')
        print('Tip: press \\ for special operations or end recording. ')
        mouse.hook(macro.appendMouse)
        while True:
            op = keyboard.read_event()
            if op.name == '\\':
                help = '\\ : \\, t : sleep, esc : stop'
                print(help, end='\r', flush=True)
                opUp = passKeyUp(op)
                superKey = keyboard.read_event()
                print(' ' * len(help), end='\r')
                passKeyUp(superKey)
                if superKey.name == '\\':
                    print('\\')
                    macro.append(Action(getPos(), key=op))
                    macro.append(Action(getPos(), key=opUp))
                elif superKey.name == 't':
                    print('Sleep')
                    macro.append(Sleep(macro.default_interval))
                elif superKey.name == 'esc':
                    mouse.unhook(macro.appendMouse)
                    print('End')
                    try:
                        try:
                            while macro[0].key.name in start.lower(
                            ) and macro[0].key.event_type == 'up':
                                macro.pop(0)
                        except AttributeError:
                            pass
                    except IndexError:
                        pass
                    record.last = macro
                    return macro
                else:
                    print('Invalid super key. ', ' ' * 6)
            elif 'win' in op.name:
                print('Sorry, Windows key is reserved for Failsafe. ')
            else:
                if op.event_type == 'down':
                    print(op.name)
                macro.append(Action(getPos(), key=op))
    except MismatchError:
        return None
Esempio n. 23
0
def main():
    mouse_minute_data = {}
    keyboard_minute_data = {}
    mins = int(input('How many minutes would you like to analyze? '))
    print()
    i = 0
    while i < mins:
        mouse_events = []

        mouse.hook(mouse_events.append)
        keyboard.start_recording()

        time.sleep(60)

        mouse.unhook(mouse_events.append)
        keyboard_events = keyboard.stop_recording()

        mouse_minute_data[i + 1] = len(mouse_events)
        keyboard_minute_data[i + 1] = len(keyboard_events)

        i += 1

    for (mouse_minute,
         mouse_data), (keyboard_minute,
                       keyboard_data) in zip(mouse_minute_data.items(),
                                             keyboard_minute_data.items()):
        print('Minute ', mouse_minute, ':')
        print(mouse_data, 'mouse events')
        print(keyboard_data, 'keyboard events')
        print()

    plt.plot(mouse_minute_data.keys(),
             mouse_minute_data.values(),
             color='red',
             label='Mouse Events')
    plt.plot(keyboard_minute_data.keys(),
             keyboard_minute_data.values(),
             color='blue',
             label='Keyboard Events')
    plt.title('Productivity Analysis')
    plt.xlabel('Minutes')
    plt.ylabel('Events per minute')
    plt.legend()
    plt.show()
Esempio n. 24
0
    def do_what_teacher_said(self, msg):
        print("teacher said " + msg)
        self.timeSinceLastTeacherMsg = 0
        if msg == 'once':
            print('do it once')
        elif msg == 'l':
            if not self.screenLocked:
                self.show()
                win32gui.SetForegroundWindow(self.handle)
                keyboard.hook(self.doNothing, suppress=True)
                self.m_x, self.m_y = mouse.get_position()
                mouse.hook(self.returnMouseBack)
                self.screenLocked = True
        elif msg == 'u':
            if self.screenLocked:
                self.hide()
                keyboard.unhook_all()
                mouse.unhook_all()
                self.screenLocked = False
        elif msg == 'launchPS':
            if not (self.launchingMinecraft):
                minecraftLauncher = Worker(self.launchPS)
                minecraftLauncher.signals.result.connect(
                    self.minecraftLaunchReport)
                self.threadpool.start(minecraftLauncher)
                self.launchingMinecraft = True
            else:
                print("Minecraft is already launching")

        elif msg == 'launchPR':
            if not (self.launchingMinecraft):
                minecraftLauncher = Worker(self.launchPR)
                minecraftLauncher.signals.result.connect(
                    self.minecraftLaunchReport)
                self.threadpool.start(minecraftLauncher)
                self.launchingMinecraft = True
            else:
                print("Minecraft is already launching")
        elif msg == 'closeMine':
            if not (self.launchingMinecraft):
                closeMine()
            else:
                print("Minecraft is launching...")
Esempio n. 25
0
    def record(self, escape_key="esc"):
        """
        Records all the key press and mouse movements and return a list of recorded events.
        Pressing the escape_key stops the recording.
        Returns the recorded events.
        """
        self.stop_replay = False
        mouse.hook(self.mouse_events_queue.put)
        keyboard.start_recording(self.keyboard_events_queue)
        print("Recoding until esc is pressed...")
        keyboard.wait(escape_key)
        mouse.unhook(self.mouse_events_queue.put)
        keyboard.stop_recording()

        events_queue = self.merge(self.mouse_events_queue,
                                  self.keyboard_events_queue)
        self.events = list(events_queue.queue)
        print("Recording completed.")
        return self.events
Esempio n. 26
0
def endOrRestart():
    userInput = input("Press 'q' to quit or 'r' to restart\n")
    while True:
        if userInput == 'q':
            exit()
        elif userInput == 'r':
            ### reset global variables
            global kUnhooked
            kUnhooked = False
            global mUnhooked
            mUnhooked = False
            global mouseStatus
            mouseStatus = False
            global keyboardStatus
            keyboardStatus = False
            mouse.hook(OnMouseEvent)
            keyboard.hook(OnKeyboardEvent)
            break
        else:
            userInput = input("Please press 'q' or 'r'\n")
Esempio n. 27
0
def record():

    recorded = queue.Queue()
    m_button_state = checkMouseState(
        0x04)  # middle button down = 0 or 1. Button up = -127 or -128
    macroStart = False

    print('press middle btn to start recording')
    while not macroStart:
        new_m_button_state = checkMouseState(0x04)
        if new_m_button_state != m_button_state:
            m_button_state = new_m_button_state

            if new_m_button_state == '':

                print('Macro Recording ...')
                macroStart = True

    # global mouse 이벤트를 후킹
    mo.hook(recorded.put)
    # global Keyboard 이벤트를 후킹
    keyHooked = key.hook(recorded.put)

    until = False
    while not until:
        new_m_button_state = checkMouseState(0x04)
        if new_m_button_state != m_button_state:
            m_button_state = new_m_button_state
            if new_m_button_state == '':
                print('Macro Recording End')
                until = True

    # 후킹 종료
    mo.unhook(recorded.put)
    key.unhook(keyHooked)

    #return_list = [mo_first_pos] + list(recorded.queue)
    return_list = list(recorded.queue)
    return return_list
Esempio n. 28
0
def record():

    width = pyautogui.size()[0]
    height = pyautogui.size()[1]
    base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    mouse_events = []

    #a
    mouse.hook(mouse_events.append)
    keyboard.start_recording()
    time.sleep(.2)
    #we move to arbitrary position and press a harmless key so the keyboard and mouse events start recording at the same time.

    pyautogui.moveTo(width / 2, height / 2)  #move mouse to middle of screen
    pyautogui.press('left')

    keyboard.wait("`")  #press this key to stop recording

    mouse.unhook(mouse_events.append)
    keyboard_events = keyboard.stop_recording()
    print(base_dir)
    pickle.dump(mouse_events, open(base_dir + r'/events/mouse.p', 'wb'))
    pickle.dump(keyboard_events, open(base_dir + r'/events/keyboard.p', 'wb'))
Esempio n. 29
0
    def setup(self):
        recorded_clicks = []
        lock = Lock()
        lock.acquire()

        def onClick(event):
            if isinstance(event,
                          mouse.ButtonEvent) and event.event_type == 'up':
                x, y = mouse.get_position()
                recorded_clicks.append({'x': x, 'y': y})
                print(recorded_clicks[-1])
                if len(recorded_clicks) == 1:
                    print('Click at the top of the dynamic slider. ')
                else:
                    mouse.unhook_all()
                    self.x = recorded_clicks[0]['x']
                    self.bottom = recorded_clicks[0]['y']
                    self.top = recorded_clicks[1]['y']
                    lock.release()

        mouse.hook(onClick)
        print('Where is the dynamic slider? ')
        print('Click at the bottom of the dynamic slider. ')
        return lock
Esempio n. 30
0
    def loop(self):
        """a
        F10 to start recording
        F10 again to end recording
        :return:
        """
        while True:
            keyboard.wait("ctrl + F10")  # Waiting for 'F10' to be pressed
            self.begin()
            self.events = [
            ]  # This is the list where all the events will be stored
            mouse.hook(self.record_mouse)  # starting the mouse recording
            keyboard.hook(self.record_keyboard)  # starting the mouse recording
            keyboard.wait("ctrl + F10")  # Waiting for 'a' to be pressed
            mouse.unhook(self.record_mouse)  # Stopping the mouse recording
            keyboard.unhook(
                self.record_keyboard)  # starting the mouse recording
            self.end()


#
#
# a = ActionRecorder()
# a.loop()