Exemplo n.º 1
0
 def start(self):
     self._listener_keyboard = KeyboardListener(on_release=self.on_keyboard_release)
     self._listener_keyboard.start()
     if input("please input \"MOUSE\" to start mouse function:\n") == "MOUSE":
         self._listener_mouse = MouseListener(on_click=self.on_click)
         self._listener_mouse.start()
         self.ctl_mouse = MouseController()
Exemplo n.º 2
0
def listen_event():
    def on_click(x, y, button, pressed):

        # print('{0} {1} at {1}'.format(
        #     button,
        #     'Pressed' if pressed else 'Released',
        #     (x, y)))

        if f'{button}' == 'Button.middle' and pressed:
            print('Button Middle pressed.')
            tiles = realtime_shot()
            sync(tiles)

        # if keyboard.is_pressed('1'):
        #     return False

    def on_press(key):
        # print("Key pressed: {0}".format(key))

        if key == Key.esc:
            print("Key pressed: {0}".format(key))
            # return False
            KeyboardListener.stop()
            MouseListener.stop()

    keyboard_listener = KeyboardListener(on_press=on_press)
    mouse_listener = MouseListener(on_click=on_click)

    keyboard_listener.start()
    mouse_listener.start()
    keyboard_listener.join()
    mouse_listener.join()
Exemplo n.º 3
0
    def run(self):
        def create_record(x, y, button=None):
            end_time = time.time()
            delay = end_time - self.start_time
            record = Record((x, y), button, delay)
            self.record_tracker.add_record(record)
            self.start_time = end_time

        def on_click(x, y, button, pressed):
            if not self.recording:
                return False
            if pressed:
                create_record(x, y, button)

        def on_move(x, y):
            if not self.recording:
                return False
            create_record(x, y)

        while self.is_running:
            while self.recording:
                with MouseListener(on_click=on_click,
                                   on_move=on_move) as listener:
                    listener.join()
            time.sleep(0.1)
Exemplo n.º 4
0
 def run(self):
     with MouseListener(on_move=self.on_move,
                 on_click=self.on_click,
                 on_scroll=self.on_scroll) as m_listener,\
         KeyboardListener(on_press=self.on_press) as k_listner:
         k_listner.join()
         m_listener.join()
def start_listeners():
    with MouseListener(on_click=on_click, on_scroll=on_scroll,
                       on_move=on_move) as m_listener:
        with KeyboardListener(on_press=on_press,
                              on_release=on_release) as k_listener:
            m_listener.join()
            k_listener.join()
Exemplo n.º 6
0
 def hook_mouse_and_key(self):
     with MouseListener(on_click=self.mouse_click,
                        on_scroll=self.mouse_scroll,
                        on_move=self.mouse_move) as self.listener:
         with KeyboardListener(
                 on_press=self.key_press,
                 on_release=self.key_release) as self.listener:
             self.listener.join()
Exemplo n.º 7
0
 def listen(self):
     with MouseListener(on_move=self.on_move, on_click=self.on_click, on_scroll=self.on_scroll) as listener:
         with KeyboardListener(self.on_press, self.on_release) as listener:
             listener.join()
         try:
             listener.wait()
         finally:
             listener.stop()
Exemplo n.º 8
0
def key_listen():
    global kill_threads
    while not kill_threads:
        # if current_window == desired_window_name:
        print('test')
        with MouseListener(on_move=on_move, on_click=on_click) as listener:
            with KeyboardListener(on_press=on_press,
                                  on_release=on_release) as listener:
                listener.join()
    def start(self):
        """
        Start the input listener.

        :return: None
        """
        with MouseListener(on_click=self._on_click,
                           on_scroll=self._on_scroll) as listener:
            listener.join()
Exemplo n.º 10
0
def listener():
    try:
        with MouseListener(on_click=on_click, on_scroll=on_scroll) as listener:
            with KeyboardListener(on_release=on_release) as listener:
                listener.join()
    except:
        time.sleep(0.2)
        print('Error: Do it again!')
        listener()
Exemplo n.º 11
0
 def startListening(self):
     """ Starts Listeners together to avoid AttributeError: CFRunLoopAddSource.
     """
     with MouseListener(on_click=lambda x, y, button, pressed: Machine.on_click(self, x, y, button, pressed)) as listener:
         with KeyboardListener(on_press=lambda key: Machine.on_press(self, key)) as listener:
             #The above implementation delays the call to the frame,
             #allowing the class methods to be altered and replaced by files
             #externally and thus allowing the parameters to be bled elsewhere.
             listener.join()
Exemplo n.º 12
0
def ghost_sense():
    ''' Detects Mouse/ Keyboard Behaviors '''
    if not is_connected():
        msg = "Your system is not online. This feature requires internet!"
        msgbx.showinfo("Connection", msg)
        return
    
    THRESHOLD_VALUE = 30
    regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@]\w+[.]\w{2,3}$'
    if not re.search(regex, email.get()):
        msgbx.showerror("Ghost Sense", "Receiver's mail address not found!")
        return

    else:
        if not os.path.isdir("./output_img/"): # Make output dir if not present already
            os.mkdir("output_img")
        OUTPUT_DIR = "./output_img/"
        FILE_NAME = datetime.now().strftime("%A %m-%d-%Y_%H:%M:%S") + ".png"
        msgbx.showinfo("Ghost Sense", "Ghost Sense Activated!")

        def on_click(x, y, button, pressed):
            ''' Handles Mouse Events and
            increase the press count '''
            global  press_count
            if pressed:
                press_count += 1

            if press_count > THRESHOLD_VALUE:
                listener.stop()
        # Collect mouse events until released

        def on_press(key):
            ''' Handles Keyboard Events and
            increase the press count '''
            global press_count
            try:
                # print(key.char)
                press_count += 1

                if press_count > THRESHOLD_VALUE:
                    return False
            except AttributeError:
                print(key)
            
        # Listen for both Mouse and Keyboard events
        with MouseListener(on_click=on_click) as listener:
            with KeyboardListener(on_press=on_press) as listener:
                listener.join()

        if press_count > THRESHOLD_VALUE:
            threading.Thread(target=get_action_response, args=()).start()
            playsound("./assets/bg_music/pred_sense.mp3")
            capture_img(OUTPUT_DIR, FILE_NAME)
            threading.Thread(target=send_email, args=[email.get(), OUTPUT_DIR+FILE_NAME])
            # print("Sent!")
            msgbx.showwarning("Ghost Sense", "Unauthorized Access Detected!")
Exemplo n.º 13
0
def start_apm():
	global end_listener
	print("Stream start")
	if end_listener == True:
		return False
	else:
		with MouseListener(on_click=on_click) as listener:
			with KeyListener(on_press=on_press) as listener:
				get_apm()
				listener.join()
Exemplo n.º 14
0
 def listen(self):
     self.server = threading.Thread(target=self.accept_connections)
     self.keyboard_listener = KeyboardListener(on_press=self.on_press,
                                               on_release=self.on_release)
     self.mouse_listener = MouseListener(on_move=self.on_move,
                                         on_click=self.on_click,
                                         on_scroll=self.on_scroll)
     self.keyboard_listener.start()
     self.mouse_listener.start()
     self.server.start()
Exemplo n.º 15
0
 def start(self):
     with MouseListener(
         on_move=self.on_move,
         on_click=self.on_click,
         on_scroll=self.on_scroll) as listener:
         with KeyboardListener(
             on_press=self.on_press,
             on_release=self.on_release) as listener:
             listener.join()
             print("Stopped Recording")
Exemplo n.º 16
0
    def __init__(self):
        Thread.__init__(self)
        self.daemon = True
        kl = KeyboardListener()
        ml = MouseListener()
        self.start()

        with KeyboardListener(on_press=self.on_press,
                              on_release=self.on_release) as listener:
            listener.join()
Exemplo n.º 17
0
 def run(self):
     self.stopFlag = False
     KeyListener(on_release=self.on_release).start()
     with MouseListener(on_move=self.on_move,
                        on_click=self.on_click) as listener:
         try:
             listener.join()
         except Exception as e:
             print('Done'.format(e.args[0]))
     print('start')
Exemplo n.º 18
0
 def reload_config(self):
     self.accepted_keys = set()
     if self.config.alt_modifier:
         self.accepted_keys.add(Key.alt_l)
     for key in self.config.key_combination:
         self.accepted_keys.add(KeyCode.from_char(key))
     self.thread = {0: KeyboardListener(on_press=self.on_press, on_release=self.on_release),
                    1: MouseListener(on_click=self.on_click)}.get(self.config.input_mode)
     self.mouse_button = {0: Button.x1,
                          1: Button.x2}.get(self.config.special_mouse_press)
     self.sequence_length = len(self.config.output_sequence)
Exemplo n.º 19
0
 def __init__(self):
     Thread.__init__(self)
     self.daemon = True
     self.start()
     self.timeCheck = timeChecker()
     with MouseListener(on_click=self.timeCheck.on_click,
                        on_move=self.timeCheck.on_move,
                        on_scroll=self.timeCheck.on_scroll) as listener:
         with KeyboardListener(
                 on_press=self.timeCheck.on_press) as listener:
             listener.join()
Exemplo n.º 20
0
def mouse_clicks():
    def on_click(x, y, button, pressed):
        global total_mouse_clicks
        get_active_window()
        total_mouse_clicks += 1
        if running == False:
            MouseListener.stop()
            return False

    mouselistener = MouseListener(on_click=on_click)
    mouselistener.start()
Exemplo n.º 21
0
 def __init__(self, filename):
     # Setup the listener threads
     self.keyboard_listener = KeyboardListener(on_press=self.on_press,
                                               on_release=self.on_release)
     self.mouse_listener = MouseListener(on_move=self.on_move,
                                         on_click=self.on_click,
                                         on_scroll=self.on_scroll)
     self.count = 0
     self.delay = time.time()
     self.events = []
     self.filename = filename
Exemplo n.º 22
0
 def __init__(self, file_manager):
     self.file = ''
     self.fileManager = file_manager
     self.log = Logger('Recorder')
     self.mouseListener = MouseListener(on_click=self.onClick, on_scroll=self.onScroll, on_move=self.onMove)
     self.keyboardListener = KeyboardListener(on_press=self.onPress, on_release=self.onRelease)
     self.clock = Clock()
     self.alert = Alert('RPTool - Recording')
     self.drag_start = (0, 0)
     self.drag_end = (0, 0)
     self.verifier = Verifier()
     self.pauseTrace = False
Exemplo n.º 23
0
def listening():
    '''
    LISTENER
    '''
    try:
        with MouseListener(on_click=clicked) as listener:
            with keyboard.Listener(on_press=on_press,
                                   on_release=on_release) as listener:
                listener.join()

    except Exception as err:
        print("ErrListening-1 : {0}".format(err))
Exemplo n.º 24
0
    def __init__(self):
        threading.Thread.__init__(self)
        self.model=torch.load('model\\test_model100.m',map_location=torch.device('cpu'))
        self.img_path='data\grab1.png'
        self.img_dealer_path='data\grab_dealer.png'
        self.img_player_path='data\grab_player.png'
        self.model.eval()
        self.list=[]
        self.hit=[sg.Text('x'),sg.In(size=(5,1),enable_events=True,key='hit_x'),sg.Text('y'),sg.In(size=(5,1),enable_events=True,key='hit_y'),sg.Radio(text='hit',group_id='check',enable_events=False,key='hit_check')]
        self.stand=[sg.Text('x'),sg.In(size=(5,1),enable_events=True,key='stand_x'),sg.Text('y'),sg.In(size=(5,1),enable_events=True,key='stand_y'),sg.Radio(text='stand',group_id='check',enable_events=False,key='stand_check')]
        self.split=[sg.Text('x'),sg.In(size=(5,1),enable_events=True,key='split_x'),sg.Text('y'),sg.In(size=(5,1),enable_events=True,key='split_y'),sg.Radio(text='split',group_id='check',enable_events=False,key='split_check')]
        self.double=[sg.Text('x'),sg.In(size=(5,1),enable_events=True,key='double_x'),sg.Text('y'),sg.In(size=(5,1),enable_events=True,key='double_y'),sg.Radio(text='double',group_id='check',enable_events=False,key='double_check')]
        self.deal=[sg.Text('x'),sg.In(size=(5,1),enable_events=True,key='deal_x'),sg.Text('y'),sg.In(size=(5,1),enable_events=True,key='deal_y'),sg.Radio(text='deal',group_id='check',enable_events=False,key='deal_check')]
        self.extra1=[sg.Text('x'),sg.In(size=(5,1),enable_events=True,key='extra1_x'),sg.Text('y'),sg.In(size=(5,1),enable_events=True,key='extra1_y'),sg.Radio(text='extra1',group_id='check',enable_events=False,key='extra1_check')]
        self.extra2=[sg.Text('x'),sg.In(size=(5,1),enable_events=True,key='extra2_x'),sg.Text('y'),sg.In(size=(5,1),enable_events=True,key='extra2_y'),sg.Radio(text='extra2',group_id='check',enable_events=False,key='extra2_check')]
        self.start_end_XY_Radio=[sg.Radio(text='grab area',group_id='grab_check',enable_events=False,key='grab_check')]
        self.start_end_Y=[sg.Text('start x'),sg.In(size=(5,1),enable_events=True,key='mouse_x_start'),sg.Text('end x'),sg.In(size=(5,1),enable_events=True,key='mouse_x_end')]
        self.start_end_X=[sg.Text('start y'),sg.In(size=(5,1),enable_events=True,key='mouse_y_start'),sg.Text('end y'),sg.In(size=(5,1),enable_events=True,key='mouse_y_end')]
        self.separator=[sg.HorizontalSeparator()]
        self.image_window = [sg.Image(filename="data\MatejkoKonst3Maj1791.png",background_color='white',enable_events=True,size=(300,300),key='_image_')]

        self.column_1=[
                        self.start_end_XY_Radio,
                        self.start_end_Y,
                        self.start_end_X,
                        self.separator,
                        [sg.Text('in text'), sg.In(size=(25, 1),enable_events=False,key='in')],
                        [sg.Button('grab',key='_grab_'),sg.Button('calc',key='_calc_'),sg.Button('remove',key='_remove_') ],
                        [sg.Listbox(values=self.list,enable_events=True,size=(30,10), key='_list_',auto_size_text=True)]
                    
        ]

#        self.column_3 = [                    
#                    ,
#                    [sg.Text('out text '), sg.In(size=(25, 1),enable_events=True,key='out')],
#                    [sg.Text('extra '), sg.In(size=(25, 1),enable_events=True,key='extra')],
#                    ]

        
        self.column_2 = [
                        self.image_window
                    ]

        self.layout = [
                [sg.Column(self.column_1),sg.Column(self.column_2,key='column_2')]                
                ]

        self.window = sg.Window('BlackJack',self.layout,resizable=True)
        self.keyboard_listener=KeyboardListener(on_press=self.on_press, on_release=self.on_release)
        self.mouse_listener = MouseListener(on_move=self.on_move, on_click=self.on_click,onscroll=self.on_scroll)
        self.mouse = Controller()
        self.mouse_button = Button
        self.keyboard = Controller()
Exemplo n.º 25
0
 def start_record(self):
     self.log = open(self.replay_file, "w")
     self.init_time = time.time() * 1000  # To make microseconds
     keyboard_listener = KeyboardListener(on_press=self.__on_press,
                                          on_release=self.__on_release)
     mouse_listener = MouseListener(on_click=self.__on_click,
                                    on_scroll=self.__on_scroll)
     keyboard_listener.start()
     mouse_listener.start()
     keyboard_listener.join()
     mouse_listener.stop()
     keyboard_listener.stop()
     self.log.flush()
     self.log.close()
Exemplo n.º 26
0
def click(_id=''):
    global pos
    pos = None

    def set_xy(x, y, button, pressed):
        global pos
        pos = (x, y)
        mouse_listener.stop()

    mouse_listener = MouseListener(on_click=set_xy)
    mouse_listener.start()
    while mouse_listener.running:
        pass
    print(f'Pos{ _id }: { pos }')
    return pos
Exemplo n.º 27
0
def gaming(ip):
    port = 5000
    game_machine = socket.socket()
    game_machine.connect((ip, port))
    data = game_machine.recv(4096)
    print("Message received: ", data.decode())

    mouse = MouseController()
    mouse_listener = MouseListener(on_click=on_click)
    mouse_listener.start()

    keyboard = KeyController()
    keyboard_listener = KeyListener(on_press=on_press, on_release=on_release)
    keyboard_listener.start()

    width, height = send_resolution(game_machine)

    # Streaming video
    while True:
        # Retrieves frame
        frame = stream(game_machine)

        # Displays frame
        cv2.namedWindow("Streaming", cv2.WND_PROP_FULLSCREEN)
        cv2.setWindowProperty("Streaming", cv2.WND_PROP_FULLSCREEN,
                              cv2.WINDOW_FULLSCREEN)
        cv2.imshow("Streaming", frame)
        if cv2.waitKey(1) == 27:
            break
        game_machine.send("Received".encode())
        print("Received")

        # Send mouse position
        send_mouse_pos(game_machine, mouse, width, height)

        # Send mouse clicks
        send_mouse_clicks(game_machine, CLICKS)
        CLICKS.clear()

        # Send keyboard input
        send_keyboard_input(game_machine, KEYPRESS)
        KEYPRESS.clear()
        CURRENT_KEY.clear()

    keyboard_listener.stop()
    mouse_listener.stop()
    cv2.destroyAllWindows()
    game_machine.close()
Exemplo n.º 28
0
    def __init__(self, game_object):
        self.game_object = game_object
        self.events_list_array = []
        self.start_time = time.time()
        self.interval = 0.1
        self.mouse_count = 0
        self.mouse = Controller()
        self.keyboard_listener = KeyboardListener(on_press=self.on_press,
                                                  on_release=self.on_release)
        self.mouse_listener = MouseListener(on_move=self.on_move,
                                            on_click=self.on_click,
                                            on_scroll=self.on_scroll)

        self.keyboard_listener.start()
        self.mouse_listener.start()
        self.listener_on(True)
Exemplo n.º 29
0
def getCoordinates():
    print(
        '\nClick once on the Top-Left and once again on the Bottom-Right of the '
        'Game Screen Rectangle Area')
    coordinates = []

    def onClick(x, y, button, pressed):

        if pressed and button == Button.left:
            coordinates.append((x, y))
            if len(coordinates) >= 2:
                print('Done!')
                mlistener.stop()

    with MouseListener(on_click=onClick) as mlistener:
        mlistener.join()

    return coordinates
Exemplo n.º 30
0
    def __init__(self, parent):
        super().__init__(parent)
        self.mouselogger = MouseListener(on_click=self.on_click,
                                         on_scroll=self.on_scroll)
        self.keylogger = KeyListener(on_press=self.on_press,
                                     on_release=self.on_release)

        main_sizer_vert = wx.BoxSizer(wx.VERTICAL)
        main_sizer_vert.AddStretchSpacer()

        # Create the "Start (to Tray)"-Button
        self.wx_button_export = wx.Button(self, label="Start")
        self.wx_button_export.Bind(wx.EVT_BUTTON, self.toggle_logging)
        main_sizer_vert.Add(self.wx_button_export, 0, wx.TOP | wx.CENTER, 20)

        #set the sizer of the panel
        main_sizer_vert.AddStretchSpacer()
        self.SetSizer(main_sizer_vert)