forked from gvalkov/python-evdev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecodes.py
More file actions
74 lines (53 loc) · 1.5 KB
/
ecodes.py
File metadata and controls
74 lines (53 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# encoding: utf-8
'''
This modules exposes most integer constants defined in ``linux/input.h``.
Exposed constants::
KEY, ABS, REL, SW, MSC, LED, BTN, REP, SND, ID, EV, BUS, SYN
This module also provides numerous reverse and forward mappings that are best
illustrated by a few examples::
>>> evdev.ecodes.KEY_A
30
>>> evdev.ecodes.ecodes['KEY_A']
30
>>> evdev.ecodes.KEY[30]
'KEY_A'
>>> evdev.ecodes.REL[0]
'REL_X'
>>> evdev.ecodes.EV[evdev.EV_KEY]
'EV_KEY'
>>> evdev.ecodes.bytype[EV_REL][0]
'REL_X'
'''
from inspect import getmembers
from evdev import _ecodes
#: mapping of names to values
ecodes = {}
prefixes = 'KEY ABS REL SW MSC LED BTN REP SND ID EV BUS SYN'
g = globals()
for k,v in getmembers(_ecodes):
for i in prefixes.split():
if k.startswith(i):
g.setdefault(i, {})[v] = k
ecodes[k] = v
#: keys are a combination of all BTN and KEY codes
keys = {}
keys.update(BTN)
keys.update(KEY)
# make keys safe to use for the default list of uinput device
# capabilities
del keys[_ecodes.KEY_MAX]
del keys[_ecodes.KEY_CNT]
#: mapping of event types to other value/name mappings
bytype = {
_ecodes.EV_KEY: keys,
_ecodes.EV_ABS: ABS,
_ecodes.EV_REL: REL,
_ecodes.EV_SW: SW,
_ecodes.EV_MSC: MSC,
_ecodes.EV_LED: LED,
_ecodes.EV_REP: REP,
_ecodes.EV_SND: SND,
_ecodes.EV_SYN: SYN, }
from evdev._ecodes import *
# cheaper than whitelisting in an __all__
del k, v, i, getmembers, g, prefixes