當前位置: 首頁>>代碼示例>>Python>>正文


Python keyboard.Listener方法代碼示例

本文整理匯總了Python中pynput.keyboard.Listener方法的典型用法代碼示例。如果您正苦於以下問題:Python keyboard.Listener方法的具體用法?Python keyboard.Listener怎麽用?Python keyboard.Listener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pynput.keyboard的用法示例。


在下文中一共展示了keyboard.Listener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def main():
    # prepare audio recorder
    p = pyaudio.PyAudio()
    stream = p.open(
        format=pyaudio.paInt16,
        channels=1,
        rate=16000,
        input=True,
        stream_callback=callback)
    stream.start_stream()

    # prepare keyboard listener
    with keyboard.Listener(
            on_press=on_press, on_release=on_release) as listener:
        listener.join()

    # close up
    stream.stop_stream()
    stream.close()
    p.terminate() 
開發者ID:Pelhans,項目名稱:ZASR_tensorflow,代碼行數:22,代碼來源:demo_client.py

示例2: windows_keys_gui

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def windows_keys_gui():
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Alt" + color.END + " key to confirm the new keymapping to Ctrl..")
    with Listener(
        # on_press=on_press,
        on_release=is_ctrl_winchrome) as listener:
            listener.join()
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Win/Super" + color.END + " key to confirm the new keymapping to Alt..")
    with Listener(
        # on_press=on_press,
        on_release=is_alt_windows) as listener:
            listener.join()
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Ctrl" + color.END + " key to confirm the new keymapping to Win/Super..")
    with Listener(
        # on_press=on_press,
        on_release=is_super_winmac) as listener:
            listener.join() 
開發者ID:rbreaves,項目名稱:kinto,代碼行數:21,代碼來源:test.py

示例3: init_controls

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def init_controls(self):
        """Define keys and add listener"""
        self.controls = {
            'w': 'forward',
            's': 'backward',
            'a': 'left',
            'd': 'right',
            'Key.space': 'up',
            'Key.shift': 'down',
            'Key.shift_r': 'down',
            'q': 'counter_clockwise',
            'e': 'clockwise',
            'i': lambda speed: self.drone.flip_forward(),
            'k': lambda speed: self.drone.flip_back(),
            'j': lambda speed: self.drone.flip_left(),
            'l': lambda speed: self.drone.flip_right(),
            # arrow keys for fast turns and altitude adjustments
            'Key.left': lambda speed: self.drone.counter_clockwise(speed),
            'Key.right': lambda speed: self.drone.clockwise(speed),
            'Key.up': lambda speed: self.drone.up(speed),
            'Key.down': lambda speed: self.drone.down(speed),
            'Key.tab': lambda speed: self.drone.takeoff(),
            'Key.backspace': lambda speed: self.drone.land(),
            'p': lambda speed: self.palm_land(speed),
            't': lambda speed: self.toggle_tracking(speed),
            'r': lambda speed: self.toggle_recording(speed),
            'z': lambda speed: self.toggle_zoom(speed),
            'Key.enter': lambda speed: self.take_picture(speed)
        }
        self.key_listener = keyboard.Listener(on_press=self.on_press,
                                              on_release=self.on_release)
        self.key_listener.start()
        # self.key_listener.join() 
開發者ID:Ubotica,項目名稱:telloCV,代碼行數:35,代碼來源:telloCV.py

示例4: chromebook_keys_gui

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def chromebook_keys_gui():
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Alt" + color.END + " key to confirm the new keymapping to Ctrl..")
    with Listener(
        # on_press=on_press,
        on_release=is_ctrl_winchrome) as listener:
            listener.join()
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Ctrl" + color.END + " key to confirm the new keymapping to Alt..")
    with Listener(
        # on_press=on_press,
        on_release=is_alt_chromebook) as listener:
            listener.join()
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Search" + color.END + " key to confirm the new keymapping to Super/Win..")
    with Listener(
        # on_press=on_press,
        on_release=is_super_chromebook) as listener:
            listener.join() 
開發者ID:rbreaves,項目名稱:kinto,代碼行數:21,代碼來源:test.py

示例5: chromebook_keys_terminal

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def chromebook_keys_terminal():
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Alt" + color.END + " key to confirm the new keymapping to Super/Win..")
    with Listener(
        # on_press=on_press,
        on_release=is_super_terminal) as listener:
            listener.join()
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Ctrl" + color.END + " key to confirm the new keymapping to Ctrl..")
    with Listener(
        # on_press=on_press,
        on_release=is_ctrl_terminal) as listener:
            listener.join()
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Search" + color.END + " key to confirm the new keymapping to Alt..")
    with Listener(
        # on_press=on_press,
        on_release=is_alt_chromebook_terminal) as listener:
            listener.join() 
開發者ID:rbreaves,項目名稱:kinto,代碼行數:21,代碼來源:test.py

示例6: windows_keys_terminal

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def windows_keys_terminal():
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Alt" + color.END + " key to confirm the new keymapping to Super/Win..")
    with Listener(
        # on_press=on_press,
        on_release=is_super_terminal) as listener:
            listener.join()
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Win/Super" + color.END + " key to confirm the new keymapping to Alt..")
    with Listener(
        # on_press=on_press,
        on_release=is_alt_windows) as listener:
            listener.join()
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Ctrl" + color.END + " key to confirm the new keymapping to Ctrl..")
    with Listener(
        # on_press=on_press,
        on_release=is_ctrl_terminal) as listener:
            listener.join() 
開發者ID:rbreaves,項目名稱:kinto,代碼行數:21,代碼來源:test.py

示例7: mac_keys_gui

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def mac_keys_gui():
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Command" + color.END + " key to confirm the new keymapping to Ctrl..")
    with Listener(
        # on_press=on_press,
        on_release=is_ctrl_mac) as listener:
            listener.join()
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Alt" + color.END + " key to confirm it remains Alt..")
    with Listener(
        # on_press=on_press,
        on_release=is_alt_mac) as listener:
            listener.join()
    print()
    print(color.UNDERLINE + color.YELLOW + "Press the physical Ctrl" + color.END + " key to confirm the new keymapping to Win/Super..")
    with Listener(
        # on_press=on_press,
        on_release=is_super_winmac) as listener:
            listener.join() 
開發者ID:rbreaves,項目名稱:kinto,代碼行數:21,代碼來源:test.py

示例8: flight_data_handler

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def flight_data_handler(self, event, sender, data):
        """Listener to flight data from the drone."""
        text = str(data)
        if self.prev_flight_data != text:
            self.prev_flight_data = text 
開發者ID:Ubotica,項目名稱:telloCV,代碼行數:7,代碼來源:telloCV.py

示例9: listen

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def listen():
    listener = keyboard.Listener(on_press = on_press,
                                 on_release = on_release)
    listener.start() 
開發者ID:asingh33,項目名稱:SupervisedChromeTrex,代碼行數:6,代碼來源:main.py

示例10: run

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def run(self):
        with keyboard.Listener(
                on_press=self.on_press,
                ) as listener:
            listener.join() 
開發者ID:nikhilkumarsingh,項目名稱:clix,代碼行數:7,代碼來源:clix.py

示例11: listen_keyboard

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def listen_keyboard():
    data_path = 'Data/Train_Data/Keyboard'
    if not os.path.exists(data_path):
        os.makedirs(data_path)

    def on_press(key):
        save_event_keyboard(data_path, 1, key)

    def on_release(key):
        save_event_keyboard(data_path, 2, key)

    with key_listener(on_press=on_press, on_release=on_release) as listener:
        listener.join() 
開發者ID:ardamavi,項目名稱:Game-Bot,代碼行數:15,代碼來源:create_dataset.py

示例12: flight_data_handler

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def flight_data_handler(self, event, sender, data):
        """
            Listener to flight data from the drone.
        """
        self.battery = data.battery_percentage
        self.fly_mode = data.fly_mode
        self.throw_fly_timer = data.throw_fly_timer
        self.throw_ongoing = data.throw_fly_timer > 0

        # print("fly_mode",data.fly_mode)
        # print("throw_fly_timer",data.throw_fly_timer)
        # print("em_ground",data.em_ground)
        # print("em_sky",data.em_sky)
        # print("electrical_machinery_state",data.electrical_machinery_state)
        #print("em_sky",data.em_sky,"em_ground",data.em_ground,"em_open",data.em_open)
        #print("height",data.height,"imu_state",data.imu_state,"down_visual_state",data.down_visual_state)
        if self.is_flying != data.em_sky:            
            self.is_flying = data.em_sky
            log.debug(f"FLYING : {self.is_flying}")
            if not self.is_flying:
                self.reset()
            else:
                if self.tracking_after_takeoff:
                    log.info("Tracking on after takeoff")
                    self.toggle_tracking(True)
                    
        log.debug(f"MODE: {self.fly_mode} - Throw fly timer: {self.throw_fly_timer}") 
開發者ID:geaxgx,項目名稱:tello-openpose,代碼行數:29,代碼來源:tello_openpose.py

示例13: log_data_handler

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def log_data_handler(self, event, sender, data):
        """
            Listener to log data from the drone.
        """  
        pos_x = -data.mvo.pos_x
        pos_y = -data.mvo.pos_y
        pos_z = -data.mvo.pos_z
        if abs(pos_x)+abs(pos_y)+abs(pos_z) > 0.07:
            if self.ref_pos_x == -1: # First time we have meaningful values, we store them as reference
                self.ref_pos_x = pos_x
                self.ref_pos_y = pos_y
                self.ref_pos_z = pos_z
            else:
                self.pos_x = pos_x - self.ref_pos_x
                self.pos_y = pos_y - self.ref_pos_y
                self.pos_z = pos_z - self.ref_pos_z
        
        qx = data.imu.q1
        qy = data.imu.q2
        qz = data.imu.q3
        qw = data.imu.q0
        self.yaw = quat_to_yaw_deg(qx,qy,qz,qw)
        
        if self.write_log_data:
            if self.write_header:
                self.log_file.write('%s\n' % data.format_cvs_header())
                self.write_header = False
            self.log_file.write('%s\n' % data.format_cvs()) 
開發者ID:geaxgx,項目名稱:tello-openpose,代碼行數:30,代碼來源:tello_openpose.py

示例14: main

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def main():
    switcher = Switcher()

    with keyboard.Listener(
            on_press=switcher.on_press,
            on_release=switcher.on_release) as listener:
        listener.join() 
開發者ID:yamnikov-oleg,項目名稱:switch-layout,代碼行數:9,代碼來源:switch-layout.py

示例15: _start

# 需要導入模塊: from pynput import keyboard [as 別名]
# 或者: from pynput.keyboard import Listener [as 別名]
def _start(self):
        with Listener(on_press=self.on_press, on_release=self.on_release) as self.listener:
            self.listener.join() 
開發者ID:Pure-L0G1C,項目名稱:Loki,代碼行數:5,代碼來源:keylogger.py


注:本文中的pynput.keyboard.Listener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。