zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    12月15日,progress_dispaly
    Android studio和Genymotion-VirtualBox的配合使用
    JDK7动态代理源码分析
    跟踪mqttv3源码(二)
    跟踪mqttv3源码(一)
    Spring自定义标签
    Eclipse发布Maven项目到远程服务器
    结合实际项目分析pom.xml
    Maven的安装环境配置
    PHP7新特性
  • 原文地址:https://www.cnblogs.com/winditsway/p/5665838.html
Copyright © 2011-2022 走看看