当前位置: 首页>>代码示例>>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;未经允许,请勿转载。