本文整理汇总了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
]
}
)
示例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)
示例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
示例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")
示例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()
示例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))
示例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
示例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
示例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
示例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
########################################################################################################################
示例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()
示例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()
示例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()
示例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()
示例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()