예제 #1
0
    def play(self, speed_factor=1.0) -> None:
        if not self.data:
            raise RuntimeError("`data` cannot be None")
        if "events" not in self.data:
            raise RuntimeError("`data['events']` cannot be None")

        mouse.play(self.data["events"], speed_factor=speed_factor)
        mouse.unhook_all()
예제 #2
0
 def start(self):
     keyboard.wait('esc')
     mouse.on_click(self.add_mouse_left_click)
     keyboard.on_press(self.add_keypress)
     keyboard.wait('esc')
     mouse.unhook_all()
     keyboard.unhook_all()
     saver.save_file(self)
예제 #3
0
    def record(self):
        print("Starting recording in 3 sec...")
        print("Press MIDDLE MOUSE button to stop recording.")
        time.sleep(3)
        print("Started recording...")
        recorded = mouse.record(button=mouse.MIDDLE, target_types=(mouse.UP, ))
        mouse.unhook_all()
        print("DONE")

        self.recording_data["events"] = recorded
        self.store_recordings(self.recording_data)
예제 #4
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()
예제 #5
0
 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()
예제 #6
0
def deactivate_hotkeys(mine_hotkey, flask_hotkey):
    '''for mine'''
    # if it's keyboard event
    if mine_hotkey[0] == keyboard.add_hotkey:
        keyboard.remove_hotkey(mine_hotkey[1])
    # if it's mouse event
    elif mine_hotkey[0] == mouse.on_button:
        pass
    '''for flask'''
    # if it's keyboard event
    if flask_hotkey[0] == keyboard.add_hotkey:
        keyboard.remove_hotkey(flask_hotkey[1])
    # if it's mouse event
    elif flask_hotkey[0] == mouse.on_button:
        mouse.unhook_all()
예제 #7
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...")
예제 #8
0
def stop_mouse(dummpy):
    mouse.unhook_all()
    showinfo_text.set(stop_info_text)
예제 #9
0
# drag from (0, 0) to (100, 100) relatively with a duration of 0.1s
mouse.drag(0, 0, 100, 100, absolute=False, duration=0.1)

# whether a button is clicked
print(mouse.is_pressed('right'))

# move 100 right & 100 down
mouse.move(100, 100, absolute=False, duration=0.2)

# make a listener when left button is clicked
mouse.on_click(lambda: print("Left Button clicked."))
# make a listener when right button is clicked
mouse.on_right_click(lambda: print("Right Button clicked."))

# remove the listeners when you want
mouse.unhook_all()

# scroll down
mouse.wheel(-1)

# scroll up
mouse.wheel(1)

# record until you click right
events = mouse.record()

# replay these events
mouse.play(events[:-1])


import mouse

#mouse.click("left")
#mouse.drag(0, 0, -100, -100, absolute=False, duration=0.1)
#mouse.move(-100, -200, absolute=False, duration=1)
#print(mouse.is_pressed("left"))

#listener
mouse.on_click(lambda: print("Left Button clicked"))

mouse.on_right_click(lambda: print("Right Button clicked"))

mouse.unhook_all()  #remove all listeners
예제 #11
0
 def stop(self):
     mouse.unhook_all()
예제 #12
0
 def _unhook(self):
     mouse.unhook_all()
     keyboard.unhook_all()
예제 #13
0
  def _get_mouse_position_on_click(self, ui_field):
    position_x, position_y = mouse.get_position()
    self.window.Element(ui_field).Update(str(position_x) + ',' + str(position_y))

    mouse.unhook_all()
예제 #14
0
 def tearDown(self):
     mouse.unhook_all()
     # Make sure there's no spill over between tests.
     self.wait_for_events_queue()
예제 #15
0
 def run(self):
     dir_path = os.path.dirname(os.path.realpath(__file__))
     print(dir_path)
     keyboard.hook(self.__key_on)
     mouse.hook(self.__mouse_on)
     keyboard.start_recording()
     win32api.keybd_event(
         160, 0, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP,
         0)
     ev_list = keyboard.stop_recording()
     if not ev_list and os.path.isfile(dir_path +
                                       r"\pywinauto_recorder.exe"):
         print("Couldn't set keyboard hooks. Trying once again...\n")
         time.sleep(0.5)
         os.system(dir_path + r"\pywinauto_recorder.exe --no_splash_screen")
         sys.exit(1)
     self.hicon = oaam.load_png(dir_path + r'\copy_clipboard.png', 64, 64)
     self.hicon_light_on = oaam.load_png(dir_path + r'\light_on.png', 40,
                                         40)
     self.hicon_light_off = oaam.load_png(dir_path + r'\light_off.png', 40,
                                          40)
     unique_candidate = None
     elements = []
     i = 0
     previous_wrapper_path = None
     unique_wrapper_path = None
     strategies = [
         Strategy.unique_path, Strategy.array_2D, Strategy.array_1D
     ]
     i_strategy = 0
     while self.mode != "Quit":
         try:
             self.main_overlay.clear_all()
             self.info_overlay.clear_all()
             x, y = win32api.GetCursorPos()
             wrapper = self.desktop.from_point(x, y)
             if wrapper is None:
                 continue
             r = wrapper.rectangle()
             self.main_overlay.add(geometry=oaam.Shape.rectangle,
                                   x=x,
                                   y=r.top + r.height() + 20,
                                   width=300,
                                   height=25,
                                   thickness=1,
                                   color=(0, 0, 0),
                                   brush=oaam.Brush.solid,
                                   brush_color=(254, 25, 255))
             self.info_overlay.add(x=x + 5,
                                   y=r.top + r.height() + 21,
                                   width=300,
                                   height=25,
                                   text="Name: " +
                                   wrapper.element_info.name,
                                   font_size=16,
                                   text_color=(0, 0, 0),
                                   color=(254, 255, 255),
                                   geometry=oaam.Shape.rectangle,
                                   thickness=0)
             self.main_overlay.add(geometry=oaam.Shape.rectangle,
                                   x=x,
                                   y=r.top + r.height() + 20 + 25 * (2 - 1),
                                   width=300,
                                   height=25,
                                   thickness=1,
                                   color=(0, 0, 0),
                                   brush=oaam.Brush.solid,
                                   brush_color=(254, 25, 255))
             self.info_overlay.add(x=x + 5,
                                   y=r.top + r.height() + 21 + 25 * (2 - 1),
                                   width=300,
                                   height=25,
                                   text="Type:" +
                                   wrapper.element_info.control_type,
                                   font_size=16,
                                   text_color=(0, 0, 0),
                                   color=(254, 255, 255),
                                   geometry=oaam.Shape.rectangle,
                                   thickness=0)
             has_value = getattr(wrapper, "get_value", None)
             if callable(has_value):
                 self.main_overlay.add(geometry=oaam.Shape.rectangle,
                                       x=x,
                                       y=r.top + r.height() + 20 + 25 *
                                       (3 - 1),
                                       width=300,
                                       height=25,
                                       thickness=1,
                                       color=(0, 0, 0),
                                       brush=oaam.Brush.solid,
                                       brush_color=(254, 25, 255))
                 self.info_overlay.add(x=x + 5,
                                       y=r.top + r.height() + 21 + 25 *
                                       (3 - 1),
                                       width=300,
                                       height=25,
                                       text="Value: " + wrapper.get_value(),
                                       font_size=16,
                                       text_color=(0, 0, 0),
                                       color=(254, 255, 255),
                                       geometry=oaam.Shape.rectangle,
                                       thickness=0)
             wrapper_path = get_wrapper_path(wrapper)
             if not wrapper_path:
                 continue
             if wrapper_path == previous_wrapper_path:
                 if (unique_wrapper_path is None) or (strategies[i_strategy]
                                                      == Strategy.array_2D):
                     i_strategy = i_strategy + 1
                     if i_strategy >= len(strategies):
                         i_strategy = len(strategies) - 1
             else:
                 i_strategy = 0
                 previous_wrapper_path = wrapper_path
                 entry_list = get_entry_list(wrapper_path)
                 unique_candidate, elements = find_element(
                     self.desktop, entry_list, window_candidates=[])
             strategy = strategies[i_strategy]
             unique_wrapper_path = None
             if strategy == Strategy.unique_path:
                 if unique_candidate is not None:
                     unique_wrapper_path = get_wrapper_path(
                         unique_candidate)
                     r = wrapper.rectangle()
                     self.main_overlay.add(geometry=oaam.Shape.rectangle,
                                           x=r.left,
                                           y=r.top,
                                           width=r.width(),
                                           height=r.height(),
                                           thickness=1,
                                           color=(0, 128, 0),
                                           brush=oaam.Brush.solid,
                                           brush_color=(0, 255, 0))
                 else:
                     for e in elements:
                         r = e.rectangle()
                         self.main_overlay.add(
                             geometry=oaam.Shape.rectangle,
                             x=r.left,
                             y=r.top,
                             width=r.width(),
                             height=r.height(),
                             thickness=1,
                             color=(0, 128, 0),
                             brush=oaam.Brush.solid,
                             brush_color=(255, 0, 0))
             if strategy == Strategy.array_1D and elements:
                 unique_array_1d = self.__find_unique_element_array_1d(
                     wrapper.rectangle(), elements)
                 if unique_array_1d is not None:
                     unique_wrapper_path = wrapper_path + unique_array_1d
                 else:
                     strategy = Strategy.array_2D
             if strategy == Strategy.array_2D and elements:
                 unique_array_2d = self.__find_unique_element_array_2d(
                     wrapper.rectangle(), elements)
                 if unique_array_2d is not None:
                     unique_wrapper_path = wrapper_path + unique_array_2d
             if unique_wrapper_path is not None:
                 self.last_element_event = ElementEvent(
                     strategy, wrapper.rectangle(), unique_wrapper_path)
                 if self.event_list and unique_wrapper_path is not None:
                     self.event_list.append(self.last_element_event)
             if self.mode == 'Record':
                 overlay_add_record_icon(self.main_overlay, 10, 10)
             elif self.mode == 'Pause':
                 overlay_add_pause_icon(self.main_overlay, 10, 10)
             elif self.mode == 'Stop':
                 self.main_overlay.clear_all()
                 overlay_add_stop_icon(self.main_overlay, 10, 10)
                 self.main_overlay.refresh()
                 while self.mode == 'Stop':
                     time.sleep(1.0)
             overlay_add_progress_icon(self.main_overlay, i, 60, 10)
             overlay_add_search_mode_icon(self.main_overlay,
                                          self.hicon_light_on, 110, 10)
             i = i + 1
             self.main_overlay.refresh()
             self.info_overlay.refresh()
             time.sleep(
                 0.005
             )  # main_overlay.clear_all() doit attendre la fin de main_overlay.refresh()
         except Exception as e:
             exc_type, exc_value, exc_traceback = sys.exc_info()
             print(
                 repr(
                     traceback.format_exception(exc_type, exc_value,
                                                exc_traceback)))
     self.main_overlay.clear_all()
     self.main_overlay.refresh()
     if self.event_list:
         self.stop_recording()
     mouse.unhook_all()
     keyboard.unhook_all()
     print("Run end")
예제 #16
0
 def run(self):
     keyboard.hook(self.__key_on)
     mouse.hook(self.__mouse_on)
     unique_candidate = None
     elements = []
     i = 0
     previous_wrapper_path = None
     unique_wrapper_path = None
     strategies = [
         core.Strategy.unique_path, core.Strategy.array_2D,
         core.Strategy.array_1D
     ]
     i_strategy = 0
     self._is_running = True
     while self._is_running:
         try:
             self.main_overlay.clear_all()
             x, y = win32api.GetCursorPos()
             wrapper = self.desktop.from_point(x, y)
             if wrapper is None:
                 continue
             wrapper_path = get_wrapper_path(wrapper)
             if not wrapper_path:
                 continue
             if wrapper_path == previous_wrapper_path:
                 if (unique_wrapper_path is None) or (
                         strategies[i_strategy] == core.Strategy.array_2D):
                     i_strategy = i_strategy + 1
                     if i_strategy >= len(strategies):
                         i_strategy = len(strategies) - 1
             else:
                 i_strategy = 0
                 previous_wrapper_path = wrapper_path
                 entry_list = core.get_entry_list(wrapper_path)
                 unique_candidate, elements = core.find_element(
                     self.desktop, entry_list, window_candidates=[])
             strategy = strategies[i_strategy]
             unique_wrapper_path = None
             if strategy == core.Strategy.unique_path:
                 if unique_candidate is not None:
                     unique_wrapper_path = get_wrapper_path(
                         unique_candidate)
                     r = wrapper.rectangle()
                     self.main_overlay.add(geometry=oaam.Shape.rectangle,
                                           x=r.left,
                                           y=r.top,
                                           width=r.width(),
                                           height=r.height(),
                                           thickness=1,
                                           color=(0, 128, 0),
                                           brush=oaam.Brush.solid,
                                           brush_color=(0, 255, 0))
                 else:
                     for e in elements:
                         r = e.rectangle()
                         self.main_overlay.add(
                             geometry=oaam.Shape.rectangle,
                             x=r.left,
                             y=r.top,
                             width=r.width(),
                             height=r.height(),
                             thickness=1,
                             color=(0, 128, 0),
                             brush=oaam.Brush.solid,
                             brush_color=(255, 0, 0))
             if strategy == core.Strategy.array_1D:
                 unique_array_1d = self.__find_unique_element_array_1d(
                     wrapper.rectangle(), elements)
                 if unique_array_1d is not None:
                     unique_wrapper_path = wrapper_path + unique_array_1d
                 else:
                     strategy = core.Strategy.array_2D
             if strategy == core.Strategy.array_2D:
                 unique_array_2d = self.__find_unique_element_array_2d(
                     wrapper.rectangle(), elements)
                 if unique_array_2d is not None:
                     unique_wrapper_path = wrapper_path + unique_array_2d
             if unique_wrapper_path is not None:
                 self.last_element_event = ElementEvent(
                     strategy, wrapper.rectangle(), unique_wrapper_path)
                 if self.event_list and unique_wrapper_path is not None:
                     self.event_list.append(self.last_element_event)
             if self.event_list:
                 overlay_add_record_icon(self.main_overlay, 10, 10)
             else:
                 overlay_add_pause_icon(self.main_overlay, 10, 10)
             overlay_add_progress_icon(self.main_overlay, i, 60, 10)
             overlay_add_search_mode_icon(self.main_overlay, 110, 10)
             i = i + 1
             self.main_overlay.refresh()
             time.sleep(
                 0.005
             )  # main_overlay.clear_all() doit attendre la fin de main_overlay.refresh()
         except Exception as e:
             exc_type, exc_value, exc_traceback = sys.exc_info()
             print(
                 repr(
                     traceback.format_exception(exc_type, exc_value,
                                                exc_traceback)))
     self.main_overlay.clear_all()
     self.main_overlay.refresh()
     if self.event_list:
         self.stop_recording()
     mouse.unhook_all()
     keyboard.unhook_all()
     print("Run end")
 def pauseBtnPressed(self):
     print("Pause Button Pressed")
     mouse.unhook_all()
예제 #18
0
 def esc(self):
     print("Pressed 'ESC'. Ending all recordings.")
     self.file.close()
     mouse.unhook_all()
     sys.exit(1)