本文整理汇总了Python中evdev.InputDevice.close方法的典型用法代码示例。如果您正苦于以下问题:Python InputDevice.close方法的具体用法?Python InputDevice.close怎么用?Python InputDevice.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类evdev.InputDevice
的用法示例。
在下文中一共展示了InputDevice.close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from evdev import InputDevice [as 别名]
# 或者: from evdev.InputDevice import close [as 别名]
def test(self):
""" Test if event device exists, is readable and has capability of
reading a keypress.
"""
if not os.access(self.path, os.R_OK | os.W_OK):
raise EvdevScannerTestError('Cannot access {}'.format(self.path))
# Check for EV_KEY capability
inputdev = InputDevice(self.path)
if 1 not in inputdev.capabilities():
raise EvdevScannerTestError('Device has no EV_KEY capability')
inputdev.close()
示例2: read_tags
# 需要导入模块: from evdev import InputDevice [as 别名]
# 或者: from evdev.InputDevice import close [as 别名]
def read_tags(tags_queue):
tag_id = ''
caps = False
worked_counter = 0
failed_counter = 0
try:
try:
dev = InputDevice('/dev/input/by-id/usb-13ba_Barcode_Reader-event-kbd')
try:
dev.grab()
except IOError as e:
print("Unable to read from RFID reader. Is it used by another process? Error: " + str(e))
# loop
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
data = categorize(event) # Save the event temporarily to introspect it
if data.scancode == 42:
if data.keystate == 1:
caps = True
if data.keystate == 0:
caps = False
if data.keystate == 1: # Down events only
if caps:
key_lookup = u'{}'.format(capscodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX
else:
key_lookup = u'{}'.format(scancodes.get(data.scancode)) or u'UNKNOWN:[{}]'.format(data.scancode) # Lookup or return UNKNOWN:XX
if (data.scancode != 42) and (data.scancode != 28):
tag_id += key_lookup # Print it all out!
if(data.scancode == 28):
if len(tag_id) == 10:
print tag_id
tags_queue.put(tag_id)
worked_counter += 1
else:
print("Leght was not 10 ({} instead). Content: {}. {} out of {} worked.".format(len(tag_id), tag_id, worked_counter, worked_counter+failed_counter))
failed_counter += 1
tag_id = ''
except OSError as e:
print("Unable to connect to RFID reader. Check if the reader is connected! And if you have the rights to access the device (e.g. try root) Error: " + str(e))
return
except (KeyboardInterrupt, SystemExit):
print("Thread killed by keyboard")
dev.close()
示例3: key_input_test
# 需要导入模块: from evdev import InputDevice [as 别名]
# 或者: from evdev.InputDevice import close [as 别名]
def key_input_test():
dev = InputDevice('/dev/input/event0')
sr.sendbit(0)
foundkeys = 0
for i in range(len(KEYPRESSES)):
if (dev.active_keys() == KEYPRESSES[i]):
print('Found Key' , KEYPRESSES[i])
foundkeys += 1
else:
print('Fail!!',dev.active_keys() ,'Expected ', KEYPRESSES[i])
sleep(0.1)
sr.sendbit(1)
if( foundkeys == 16 ):
print( 'Test Passed')
dev.close()
return True
else:
print( 'Test FAIL!!!!!!!!!!!')
dev.close()
return False
示例4: EvdevButton
# 需要导入模块: from evdev import InputDevice [as 别名]
# 或者: from evdev.InputDevice import close [as 别名]
class EvdevButton(BasePort):
""" Event device button port.
Event device button port reads keyup events from the specified event
device special file representing keyboard. A given keycode acts as
a button.
Configuration
-------------
Port accepts the following positional arguments:
#. /path/to/event_device - path to event device special file
#. scancode - scancode of trigger key
Full configuration line of evdev button is:
``button=evdev:/path/to/event_device,keycode``
"""
def __init__(self, *args):
""" Initialize port configuration.
"""
self.path = '/dev/input/event0'
self.scancode = 57
self.device = None
if len(args) >= 1:
self.path = args[0]
if len(args) >= 2:
self.scancode = int(args[1])
logger.info('Evdev button using: {} keycode={}'.format(
self.path, self.scancode))
def test(self):
""" Test if event device exists, is readable and has capability of
reading a keypress.
"""
# FIXME
pass
def open(self):
""" Open event device.
"""
logger.info('Opening evdev {}'.format(self.path))
self.device = InputDevice(self.path)
if self.device:
logger.info('Evdev button found: {}'.format(self.device))
def close(self):
""" Close event device.
"""
logger.info('Closing evdev {}'.format(self.path))
if self.is_open():
self.device.close()
self.device = None
def is_open(self):
""" Check whether the event device is open.
"""
if self.device:
return True
return False
def read(self, callback=None):
""" Read event device.
If button event is triggered a function assigned to callback
argument is run.
"""
# In order to avoid bare polling a select() is called on device
# descriptor with a reasonable timeout so the thread can be
# interrupted. In case of event read we will read and process it.
r, w, x = select.select([self.device.fileno()], [], [], 1)
if r:
e = self.device.read_one()
if e.type == ecodes.EV_KEY \
and e.value == 0 and e.code == self.scancode:
logger.debug('Trigger: {}'.format(e))
# Execute callback function
if callback and hasattr(callback, '__call__'):
callback()
def flush(self):
""" Flush event device.
"""
logger.debug('Flushing port')
while True:
r, w, x = select.select([self.device.fd], [], [], 0)
if r:
self.device.read_one()
else:
break
示例5: EvdevScanner
# 需要导入模块: from evdev import InputDevice [as 别名]
# 或者: from evdev.InputDevice import close [as 别名]
class EvdevScanner(BasePort):
""" Event scanner button port.
Event device scanner port reads keyup events from the specified event
device special file representing keyboard into a buffer. Once a RETURN
key is read the buffer is flushed as a read code.
Most barcode readers act as a HID keyboard. In order to make them work
with this port they must be configured to send RETURN after code.
Configuration
-------------
Port accepts the following positional arguments:
#. /path/to/event_device - path to event device special file
Full configuration line of evdev button is:
``scanner=evdev:/path/to/event_device``
"""
# NOTE This is really incomplete but it works with ticket generator just
# fine. Only missing symbols from Code39 (Standard) are %
CODE39 = {
2: '1', 3: '2', 4: '3', 5: ['4', '$'], 6: ['5', '%'],
7: '6', 8: '7', 9: ['8', '*'], 10: '9', 11: '0', 12: '-',
13: '+', 16: 'Q', 17: 'W', 18: 'E', 19: 'R', 20: 'T', 21: 'Y',
22: 'U', 23: 'I', 24: 'O', 25: 'P', 30: 'A', 31: 'S', 32: 'D',
33: 'F', 34: 'G', 35: 'H', 36: 'J', 37: 'K', 38: 'L', 44: 'Z',
45: 'X', 46: 'C', 47: 'V', 48: 'B', 49: 'N', 50: 'M', 52: '.',
53: '/', 57: ' ', }
def __init__(self, *args):
""" Initialize port configuration.
"""
self.path = '/dev/input/event0'
self.device = None
if len(args) >= 1:
self.path = args[0]
self._buffer = ''
self._shift = False
self._caps = False
logger.debug('Evdev scanner using: {}'.format(self.path))
def test(self):
""" Test if event device exists, is readable and has capability of
reading a keypress.
"""
if not os.access(self.path, os.R_OK | os.W_OK):
raise EvdevScannerTestError('Cannot access {}'.format(self.path))
# Check for EV_KEY capability
inputdev = InputDevice(self.path)
if 1 not in inputdev.capabilities():
raise EvdevScannerTestError('Device has no EV_KEY capability')
inputdev.close()
def open(self):
""" Open event device.
"""
logger.debug('Opening evdev {}'.format(self.path))
self.device = InputDevice(self.path)
if self.device:
logger.info('Evdev scanner found: {}'.format(self.device))
def close(self):
""" Close event device.
"""
logger.debug('Closing evdev {}'.format(self.path))
if self.is_open():
self.device.close()
def is_open(self):
""" Check whether the event device is open.
"""
if self.device:
return True
return False
def read(self, callback=None):
""" Read event device.
If button event is triggered a function assigned to callback
argument is run.
"""
# In order to avoid bare polling a select() is called on device
# descriptor with a reasonable timeout so the thread can be
# interrupted. In case of event read we will read and process it.
r, w, x = select.select([self.device.fileno()], [], [], 1)
if r:
event = self.device.read_one()
#.........这里部分代码省略.........