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


Python ecodes.EV_KEY屬性代碼示例

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


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

示例1: __init__

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def __init__(self, can_id):
        self.can_id = can_id
        axis_cap = AbsInfo(-32700,32700,0,0,0,0)
        self._ev = UInput(name='vjoy',
            events={
                 ecodes.EV_ABS: [
                     (ecodes.ABS_X, axis_cap),
                     (ecodes.ABS_Y, axis_cap),
                     (ecodes.ABS_Z, axis_cap)
                 ],
                 ecodes.EV_KEY: [
                     ecodes.BTN_TRIGGER, 
                     ecodes.BTN_TOP, 
                     ecodes.BTN_TOP2
                 ]
            }
        ) 
開發者ID:fishpepper,項目名稱:pyUSBtin,代碼行數:19,代碼來源:elobau_j6_joystick.py

示例2: read_events

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def read_events(req_device):
    for device in list_devices():
        # Look in all 3 identifiers + event number
        if req_device in device or \
           req_device == device[0].replace("/dev/input/event", ""):
            found = evdev.InputDevice(device[0])

    if 'found' not in locals():
        print("Device not found. \n"
              "Please use --list-devices to view a list of available devices.")
        return

    print(found)
    print("To stop, press Ctrl-C")

    for event in found.read_loop():
        try:
            if event.type == evdev.ecodes.EV_KEY:
                categorized = evdev.categorize(event)
                if categorized.keystate == 1:
                    keycode = categorized.keycode if type(categorized.keycode) is str \
                        else " | ".join(categorized.keycode)
                    print("Key pressed: %s (%s)" % (keycode, categorized.scancode))
        except KeyError:
            if event.value:
                print("Unknown key (%s) has been pressed." % event.code)
            else:
                print("Unknown key (%s) has been released." % event.code) 
開發者ID:philipl,項目名稱:evdevremapkeys,代碼行數:30,代碼來源:evdevremapkeys.py

示例3: change_state

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def change_state(self, event):
        if event.type == ecodes.EV_SYN:
            current = time.monotonic()
            diff = 20/1000
            if current - self.last < diff and not self.change:
                return
            self.last = current
            speed = 1
            self.state[3] = min(127, max(-127, int(self.x * speed))) & 255
            self.state[4] = min(127, max(-127, int(self.y * speed))) & 255
            self.state[5] = min(127, max(-127, self.z)) & 255
            self.x = 0
            self.y = 0
            self.z = 0
            self.change = False
            BluetoothDevice.send_current(self.state)
        if event.type == ecodes.EV_KEY:
            debug("Key event %s %d", ecodes.BTN[event.code], event.value)
            self.change = True
            if event.code >= 272 and event.code <= 276 and event.value < 2:
                button_no = event.code - 272
                if event.value == 1:
                    self.state[2] |= 1 << button_no
                else:
                    self.state[2] &= ~(1 << button_no)
        if event.type == ecodes.EV_REL:
            if event.code == 0:
                self.x += event.value
            if event.code == 1:
                self.y += event.value
            if event.code == 8:
                self.z += event.value 
開發者ID:quangthanh010290,項目名稱:keyboard_mouse_emulate_on_raspberry,代碼行數:34,代碼來源:mouse_client.py

示例4: _handle_event

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def _handle_event(self, flags):
    logging.debug("Key_pin_listener handler start")
    if flags != select.POLLIN:
      logging.error("Key_pin_listener read failure: %s", str(flags))
      try:
        events = self.dev.read()
        logging.error("Key_pin_listener still got events: %s ?!?", str(events))
      except IOError as e:
        logging.error("Key_pin_listener read failed: %s", str(e))
      logging.error("Key_pin_listener removing key pin FD")
      self.iomanager.remove_file(self.dev)
    else:
      try:
        for event in self.dev.read():
          logging.debug("key pin event: %s", event)
          if event.type == ecodes.EV_KEY:
            code = int(event.code)
            val = int(event.value)
            if code in self.keys:
              key = self.keys[code]
              if (key.edge == 0xff or val == key.edge) and key.callback:
                logging.debug("sending key pin event to handler %s", str(key))
                key.callback(key, event)
                logging.debug("key pin event handler done")
      except IOError as e:
        logging.error("Key_pin_listener read failed in read event: %s", str(e))
        self.iomanager.remove_file(self.dev)
    logging.debug("Key_pin_listener handler end") 
開發者ID:intelligent-agent,項目名稱:redeem,代碼行數:30,代碼來源:Key_pin.py

示例5: signal

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def signal(self, x, y, z, b0, b1, b2):
       self._ev.write(ecodes.EV_ABS, ecodes.ABS_X, x)
       self._ev.write(ecodes.EV_ABS, ecodes.ABS_Y, y)
       self._ev.write(ecodes.EV_ABS, ecodes.ABS_Z, z)
       self._ev.write(ecodes.EV_KEY, ecodes.BTN_TRIGGER, b0)
       self._ev.write(ecodes.EV_KEY, ecodes.BTN_TOP,     b1)
       self._ev.write(ecodes.EV_KEY, ecodes.BTN_TOP2,    b2)
       self._ev.syn() 
開發者ID:fishpepper,項目名稱:pyUSBtin,代碼行數:10,代碼來源:elobau_j6_joystick.py

示例6: listen_for_events

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def listen_for_events(dev):
    for event in dev.read_loop():
        if event.type == ecodes.EV_KEY:
            print dev.name+":  "+str(categorize(event)) 
開發者ID:CRImier,項目名稱:pyLCI,代碼行數:6,代碼來源:debug_listener.py

示例7: runner

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def runner(self):
        """Blocking event loop which just calls supplied callbacks in the keymap."""
        try:
            while not self.stop_flag:
                event = self.device.read_one()
                if event is not None and event.type == ecodes.EV_KEY:
                    key = ecodes.keys[event.code]
                    value = event.value
                    if value == 0 and self.enabled:
                        self.send_key(key)
                sleep(0.01)
        except IOError as e: 
            if e.errno == 11:
                #raise #Uncomment only if you have nothing better to do - error seems to appear at random
                pass 
開發者ID:CRImier,項目名稱:pyLCI,代碼行數:17,代碼來源:hid.py

示例8: event_loop

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def event_loop(self):
        for event in self.dev.read_loop():
            if event.type == ecodes.EV_KEY and event.value < 2:
                self.change_state_button(event)
            elif event.type == ecodes.EV_REL:
                self.change_state_movement(event)
            try:
                self.send_input()
            except:
                print("Couldn't send mouse input")
                break

    # forward mouse events to the dbus service 
開發者ID:AnesBenmerzoug,項目名稱:Bluetooth_HID,代碼行數:15,代碼來源:mouse_client.py

示例9: event_loop

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def event_loop(self):
        for event in self.dev.read_loop():
            # only bother if we hit a key and its an up or down event
            if event.type == ecodes.EV_KEY and event.value < 2:
                self.change_state(event)
                try:
                    self.send_input()
                except:
                    print("Couldn't send keyboard input")
                    break

    # forward keyboard events to the dbus service 
開發者ID:AnesBenmerzoug,項目名稱:Bluetooth_HID,代碼行數:14,代碼來源:keyboard_client.py

示例10: combined_event_loop

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def combined_event_loop(self):
        print("Starting combined event loop")
        devices = {dev.fd: dev for dev in [self.keyboard, self.mouse] if dev is not None}
        while True:
            r, w, e = select(devices, [], [])
            for fd in r:
                if devices[fd] == self.keyboard:
                    for event in self.keyboard.read():
                        # only bother if we hit a key and its an up or down event
                        if event.type == ecodes.EV_KEY and event.value < 2:
                            self.change_keyboard_state(event)
                            try:
                                self.send_keyboard_input()
                            except:
                                break

                else:
                    for event in self.mouse.read():
                        if event.type == ecodes.EV_KEY and event.value < 2:
                            self.change_state_button(event)
                        elif event.type == ecodes.EV_REL:
                            self.change_state_movement(event)
                        try:
                            self.send_mouse_input()
                        except :
                            break

######################################################################################################################## 
開發者ID:AnesBenmerzoug,項目名稱:Bluetooth_HID,代碼行數:30,代碼來源:devices_client.py

示例11: ButtonEvent

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def ButtonEvent(channel):                                                 
    if GPIO.input(JUMP_PIN) == 1:
        ui.write(e.EV_KEY, e.KEY_LEFTALT, 0)  
        ui.syn()
    if GPIO.input(JUMP_PIN) == 0:
        ui.write(e.EV_KEY, e.KEY_LEFTALT, 1) 
        ui.syn()
    if GPIO.input(FIRE_PIN) == 1:
        ui.write(e.EV_KEY, e.KEY_LEFTCTRL, 0)  
        ui.syn()
    if GPIO.input(FIRE_PIN) == 0:
        ui.write(e.EV_KEY, e.KEY_LEFTCTRL, 1) 
        ui.syn() 
開發者ID:raspberrypi-tw,項目名稱:gpio-game-console,代碼行數:15,代碼來源:gaming_console.py

示例12: button_p_handler

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def button_p_handler(button, pressed):
    keycode = KEYCODES[button]
    print("Press: {}".format(keycode))
    ui.write(e.EV_KEY, keycode, 1)
    ui.syn() 
開發者ID:pimoroni,項目名稱:button-shim,代碼行數:7,代碼來源:keyboard.py

示例13: button_r_handler

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def button_r_handler(button, pressed):
    keycode = KEYCODES[button]
    print("Release: {}".format(keycode))
    ui.write(e.EV_KEY, keycode, 0)
    ui.syn() 
開發者ID:pimoroni,項目名稱:button-shim,代碼行數:7,代碼來源:keyboard.py

示例14: press

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def press( self ):
		self.isPressed = time.time()
		self.injector.write(e.EV_KEY, self.command, 1)
		self.injector.syn()
		self.waitForRelease() 
開發者ID:mholgatem,項目名稱:GPIOnext,代碼行數:7,代碼來源:device.py

示例15: release

# 需要導入模塊: from evdev import ecodes [as 別名]
# 或者: from evdev.ecodes import EV_KEY [as 別名]
def release( self ):
		if self.isPressed:
			self.isPressed = 0
			self.injector.write(e.EV_KEY, self.command, 0)
			self.injector.syn() 
開發者ID:mholgatem,項目名稱:GPIOnext,代碼行數:7,代碼來源:device.py


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