X Tutup
Skip to content

Commit 543c378

Browse files
committed
add device.read_loop() - blocking version of device.read()
1 parent f9c076c commit 543c378

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Enhancements:
3737

3838
- Add ``InputDevice.version`` - the value of ``EVIOCGVERSION``.
3939

40+
- Add ``device.read_loop()``
41+
4042
- Replace the DeviceInfo class with a namedtuple.
4143

4244
Fixes:

evdev/device.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# encoding: utf-8
22

33
import os
4+
from select import select
45
from collections import namedtuple
56

67
from evdev import _input, ecodes, util
@@ -200,6 +201,14 @@ def read_one(self):
200201
if event:
201202
return InputEvent(*event)
202203

204+
def read_loop(self):
205+
'''Enter a polling loop that yields input events.'''
206+
207+
while True:
208+
r,w,x = select([self.fd], [], [])
209+
for event in self.read():
210+
yield event
211+
203212
def read(self):
204213
'''
205214
Read multiple input events from device. This function returns a
@@ -219,7 +228,7 @@ def read(self):
219228

220229
@property
221230
def repeat(self):
222-
''' Get or set the keyboard repeat rate (in characters per
231+
'''Get or set the keyboard repeat rate (in characters per
223232
minute) and delay (in milliseconds).'''
224233

225234
return KbdInfo(*_input.ioctl_EVIOCGREP(self.fd))

0 commit comments

Comments
 (0)
X Tutup