evdev module-----ecodes.py

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

 

转载于:https://www.cnblogs.com/winditsway/p/5665838.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值