本文整理汇总了Python中evdev.InputDevice方法的典型用法代码示例。如果您正苦于以下问题:Python evdev.InputDevice方法的具体用法?Python evdev.InputDevice怎么用?Python evdev.InputDevice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类evdev
的用法示例。
在下文中一共展示了evdev.InputDevice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __connect
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def __connect(self):
device_addr, hidraw_device, event_device = self.__find_device()
if device_addr is None:
return False
self.__report_fd = os.open(hidraw_device, os.O_RDWR | os.O_NONBLOCK)
self.__fd = FileIO(self.__report_fd, "rb+", closefd=False)
self.__input_device = InputDevice(event_device)
self.__input_device.grab()
buf = bytearray(38)
buf[0] = 0x02
try:
return bool(fcntl.ioctl(self.__fd, 3223734279, bytes(buf)))
except:
pass
if self.recv():
self.update_controller()
示例2: run
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def run(self):
logging.debug("Input thread started.")
dev = InputDevice(self._controller.event_device)
fds = {dev.fd: dev}
while not self._stop:
try:
r, _, _ = select(fds, [], [], 0.1)
for fd in r:
for event in fds[fd].read():
self._handler(event)
except IOError as e:
logging.warning("Input I/O error. {}".format(e))
time.sleep(3)
dev = InputDevice(self._controller.event_device)
# TODO: Handle FileNotFoundError.
fds = {dev.fd: dev}
logging.debug("Input thread stopped.")
示例3: _open_input_devices
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def _open_input_devices(self):
if self._opened:
return True
for input_device in self._input_devices:
try:
event_device = evdev.InputDevice(input_device)
self._event_devices.append(event_device)
task = ensure_future(self._evdev_callback(event_device))
task.add_done_callback(functools.partial(self._evdev_close, event_device))
self._tasks.append(task)
self._logger.info('Opened event device %s', event_device)
except Exception as err:
self._logger.exception("Failed to open device: %s", input_device, exc_info=err)
if self._event_devices:
self._opened = True
return self._opened
示例4: find_input
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def find_input(device):
name = device.get('input_name', None)
phys = device.get('input_phys', None)
fn = device.get('input_fn', None)
if name is None and phys is None and fn is None:
raise NameError('Devices must be identified by at least one ' +
'of "input_name", "input_phys", or "input_fn"')
devices = [InputDevice(fn) for fn in evdev.list_devices()]
for input in devices:
if name is not None and input.name != name:
continue
if phys is not None and input.phys != phys:
continue
if fn is not None and input.path != fn:
continue
if input.path in registered_devices:
continue
return input
return None
示例5: run
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def run(self):
global pairing
devices = [evdev.InputDevice(file_name) for file_name in evdev.list_devices()]
for dev in devices:
if 'PRP0001' in dev.name:
device = evdev.InputDevice(dev.fn)
while 1:
r,w,x = select([device.fd], [], [], 0.1)
if r:
for event in device.read():
if event.code == ecodes.KEY_HOME and event.value == 1:
if pairing == False:
pairing = True
buttonwait.set()
# Following function is heavily inspired by BlueZ tests
示例6: RequestPasskey
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def RequestPasskey(self, device):
print("RequestPasskey (%s)" % (device))
passkey = ""
kb = ev.InputDevice(glob.glob('/dev/input/by-path/*event-kbd')[0])
print(kb)
for event in kb.read_loop():
data = ev.categorize(event)
if event.type != ev.ecodes.EV_KEY:
continue
elif data.keystate == 0: # ignore keyup
continue
key = ev.ecodes.KEY[event.code][4:]
if key == 'ENTER': # we are done
break
elif key in ['1','2','3','4','5','6','7','8','9','0']:
passkey = passkey + key
set_trusted(device)
return int(passkey)
示例7: get_scanner_device
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def get_scanner_device(self):
"""Finds connected device matching device_name.
Returns:
The file for input events that read_input can listen to
"""
devices = [evdev.InputDevice(x) for x in evdev.list_devices()]
for dev in devices:
if str(dev.name) == self._device_name:
return dev
raise NoMatchingDevice(
self._device_name, [d.name for d in devices], "check permissions?"
)
示例8: set_autocenter
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def set_autocenter(self, device_id, autocenter):
autocenter = str(int(65535 * autocenter / 100))
logging.debug("Setting autocenter strength: " + autocenter)
path = self.checked_device_file(device_id, "autocenter")
if path:
with open(path, "w") as file:
file.write(autocenter)
else:
dev = InputDevice(self.devices[device_id]['dev'])
dev.write(ecodes.EV_FF, ecodes.FF_AUTOCENTER, int(autocenter))
return True
示例9: set_ff_gain
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def set_ff_gain(self, device_id, gain):
gain = str(int(65535 * gain / 100))
logging.debug("Setting FF gain: " + gain)
path = self.checked_device_file(device_id, "gain")
if path:
with open(path, "w") as file:
file.write(gain)
else:
dev = InputDevice(self.devices[device_id]['dev'])
dev.write(ecodes.EV_FF, ecodes.FF_GAIN, int(gain))
示例10: change_device
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def change_device(self, device_id):
if device_id == None:
self.device = None
return
self.device = InputDevice(self.wheels.id_to_dev(device_id))
if not self.wheels.check_permissions(device_id):
self.install_udev_file()
self.read_settings(device_id)
self.ui.set_ffbmeter_overlay(False)
self.ui.set_wheel_range_overlay('never')
示例11: set_emulation_mode
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def set_emulation_mode(self, device_id, mode):
self.device.close()
self.device = None
self.wheels.set_mode(device_id, mode)
self.emulation_mode = mode
self.device = InputDevice(self.wheels.id_to_dev(device_id))
self.ui.set_device_id(device_id)
self.read_settings(device_id, True)
示例12: _default_joystick
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def _default_joystick(self):
"""Return the first (sorted) device with an absolute X axis."""
for fn in sorted(evdev.list_devices()):
device = evdev.InputDevice(fn)
for axis, info in device.capabilities().get(evdev.ecodes.EV_ABS, []):
if axis == evdev.ecodes.ABS_X:
return device
raise IOError('No joystick device found')
示例13: list_devices
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def list_devices(self):
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
def hasAKey(device):
caps = device.capabilities(verbose=True)
events = caps.get(('EV_KEY', 1), [])
a_keys = [e for e in events if e[0] == 'KEY_A']
return len(a_keys) > 0
return list(filter(hasAKey, devices))
示例14: reader_thread
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def reader_thread(self):
# A mapping of file descriptors (integers) to InputDevice instances.
devices = {dev.fd: dev for dev in self.devices}
while True:
r, w, x = select(devices, [], [])
for fd in r:
for event in devices[fd].read():
ce = evdev.categorize(event)
if isinstance(ce, evdev.KeyEvent):
self.handle_key(ce.keycode, ce.keystate)
return
示例15: list_devices
# 需要导入模块: import evdev [as 别名]
# 或者: from evdev import InputDevice [as 别名]
def list_devices():
devices = [InputDevice(fn) for fn in evdev.list_devices()]
for device in reversed(devices):
yield [device.fn, device.phys, device.name]