scancode_camera的scancode - CSDN
精华内容
参与话题
  • wx.scanCode二维码识别并跳转

    千次阅读 2020-02-06 15:03:48
    wx.scanCode二维码识别并跳转 以下是效果图 扫二维码----js代码 Toscan:function(){ var _this = this; wx.scanCode({ success: (res) => { wx.navigateTo({ url: '../info/info?messag...

    wx.scanCode二维码识别并跳转

    以下是效果图

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    扫二维码----js代码

    Toscan:function(){
          var _this = this;
          wx.scanCode({
            success: (res) => {
              wx.navigateTo({
                url: '../info/info?message='+res.result,
              })
              var show = res.result;
    
              console.log(show)
              _this.setData({
                show: show
              })
            }
        })
      }
    

    跳转页面----js代码

     onLoad: function (options) {
        this.setData({
          message:options.message
        })
      },
    
    展开全文
  • Scancode

    2010-09-14 15:34:03
    附:scancode表 MAKE code - code generated when key is pressed. BREAK code - code generated when key is released.     Keyboard Scan Codes Set 1 KEY Name Define Value (decimal) ...

    附:scancode表

    MAKE code - code generated when key is pressed.
    BREAK code - code generated when key is released.

     

     

    Keyboard Scan Codes Set 1
    KEY Name Define Value (decimal) Label Additional Label MAKE (hex) BREAK (hex)
    Escape 1 Esc 0x01 0x81
    1 2 1 ! 0x02 0x82
    2 3 2 @ 0x03 0x83
    3 4 3 # 0x04 0x84
    4 5 4 $ 0x05 0x85
    5 6 5 % 0x06 0x86
    6 7 6 ^ 0x07 0x87
    7 8 7 & 0x08 0x88
    8 9 8 * 0x09 0x89
    9 10 9 ( 0x0A 0x8A
    0 11 0 ) 0x0B 0x8B
    Minus 12 - _ 0x0C 0x8C
    Equal 13 = + 0x0D 0x8D
    BackSpace 14 BackSpace 0x0E 0x8E
    Tab 15 Tab 0x0F 0x8F
    Q 16 Q 0x10 0x90
    W 17 W 0x11 0x91
    E 18 E 0x12 0x92
    R 19 R 0x13 0x93
    T 20 T 0x14 0x94
    Y 21 Y 0x15 0x95
    U 22 U 0x16 0x96
    I 23 I 0x17 0x97
    O 24 O 0x18 0x98
    P 25 P 0x19 0x99
    LBrace 26 [ { 0x1A 0x9A
    RBrace 27 ] } 0x1B 0x9B
    Enter 28 Enter 0x1C 0x9C
    LCtrl 29 Ctrl (left) 0x1D 0x9D
    A 30 A 0x1E 0x9E
    S 31 S 0x1F 0x9F
    D 32 D 0x20 0xA0
    F 33 F 0x21 0xA1
    G 34 G 0x22 0xA2
    H 35 H 0x23 0xA3
    J 36 J 0x24 0xA4
    K 37 K 0x25 0xA5
    L 38 L 0x26 0xA6
    SemiColon 39 ; : 0x27 0xA7
    Quote 40 ' " 0x28 0xA8
    Tilde 41 ` ~ 0x29 0xA9
    LShift 42 Shift (left) 0x2A 0xAA
    BackSlash 43 \ | 0x2B 0xAB
    Z 44 Z 0x2C 0xAC
    X 45 X 0x2D 0xAD
    C 46 C 0x2E 0xAE
    V 47 V 0x2F 0xAF
    B 48 B 0x30 0xB0
    N 49 N 0x31 0xB1
    M 50 M 0x32 0xB2
    Comma 51 , < 0x33 0xB3
    Period 52 . > 0x34 0xB4
    Slash 53 / ? 0x35 0xB5
    RShift 54 Shift (right) 0x36 0xB6
    KP_Multiply 55 * 0x37 0xB7
    LAlt 56 Alt (left) 0x38 0xB8
    Space 57 SpaceBar 0x39 0xB9
    CapsLock 58 CapsLock 0x3A 0xBA
    F1 59 F1 0x3B 0xBB
    F2 60 F2 0x3C 0xBC
    F3 61 F3 0x3D 0xBD
    F4 62 F4 0x3E 0xBE
    F5 63 F5 0x3F 0xBF
    F6 64 F6 0x40 0xC0
    F7 65 F7 0x41 0xC1
    F8 66 F8 0x42 0xC2
    F9 67 F9 0x43 0xC3
    F10 68 F10 0x44 0xC4
    NumLock 69 NumLock 0x45 0xC5
    ScrollLock 70 Scroll Lock 0x46 0xC6
    KP_7 71 7 Home 0x47 0xC7
    KP_8 72 8 ArrowU 0x48 0xC8
    KP_9 73 9 PgUp 0x49 0xC9
    KP_Minus 74 - 0x4A 0xCA
    KP_4 75 4 ArrowL 0x4B 0xCB
    KP_5 76 5 0x4C 0xCC
    KP_6 77 6 ArrowR 0x4D 0xCD
    KP_Plus 78 + 0x4E 0xCE
    KP_1 79 1 End 0x4F 0xCF
    KP_2 80 2 ArrowD 0x50 0xD0
    KP_3 81 3 PgDn 0x51 0xD1
    KP_0 82 0 Ins 0x52 0xD2
    KP_Decimal 83 . Del 0x53 0xD3
    F11 84 F11 0x57 0xD7
    F12 85 F12 0x58 0xD8
    PrintScreen 86 Print Screen SysRq 0xE0 0x2A 0xE0 0x37 0xE0 0xB7 0xE0 0xAA
    Pause 87 Pause Break 0xE1 0x1D 0x45 0xE1 0x9D 0xC5 -NONE-
    KP_Enter 88 Enter 0xE0 0x1C 0xE0 0x9C
    RCtrl 89 Ctrl (right) 0xE0 0x1D 0xE0 0x9D
    KP_Slash 90 / 0xE0 0x35 0xE0 0xB5
    RAlt 91 Alt (right) 0xE0 0x38 0xE0 0xB8
    Home 92 Home 0xE0 0x47 0xE0 0xC7
    ArrowU 93 ArrowU 0xE0 0x48 0xE0 0xC8
    PageUp 94 Page Up 0xE0 0x49 0xE0 0xC9
    ArrowL 95 ArrowL 0xE0 0x4B 0xE0 0xCB
    ArrowR 96 ArrowR 0xE0 0x4D 0xE0 0xCD
    End 97 End 0xE0 0x4F 0xE0 0xCF
    ArrowD 98 ArrowD 0xE0 0x50 0xE0 0xD0
    PageDown 99 Page Down 0xE0 0x51 0xE0 0xD1
    Insert 100 Insert 0xE0 0x52 0xE0 0xD2
    Delete 101 Delete 0xE0 0x53 0xE0 0xD3
    LWin 102 LWin 0xE0 0x5B 0xE0 0xDB
    RWin 103 RWin 0xE0 0x5C 0xE0 0xDC
    Menu 104 Menu 0xE0 0x5D 0xE0 0xDD
    Power 105 Power 0xE0 0x5E 0xE0 0xDE
    Sleep 106 Sleep 0xE0 0x5F 0xE0 0xDF
    Wake 107 Wake 0xE0 0x63 0xE0 0xE3
    NextTrack 108 Next Track 0xE0 0x19 0xE0 0x99
    PreviousTrack 109 Previous Track 0xE0 0x10 0xE0 0x90
    Stop 110 Stop 0xE0 0x24 0xE0 0xA4
    Play_Pause 111 Play_Pause 0xE0 0x22 0xE0 0xA2
    Mute 112 Mute 0xE0 0x20 0xE0 0xA0
    VolumeUp 113 Volume Up 0xE0 0x30 0xE0 0xB0
    VolumeDown 114 Volume Down 0xE0 0x2E 0xE0 0xAE
    MediaSelect 115 Media 0xE0 0x6D 0xE0 0xED
    EMail 116 E-Mail 0xE0 0x6C 0xE0 0xEC
    Calculator 117 Calculator 0xE0 0x21 0xE0 0xA1
    MyComputer 118 My Computer 0xE0 0x6B 0xE0 0xEB
    WWWSearch 119 WWW Search 0xE0 0x65 0xE0 0xE5
    WWWHome 120 WWW Home 0xE0 0x32 0xE0 0xB2
    WWWBack 121 WWW Back 0xE0 0x6A 0xE0 0xEA
    WWWForward 122 WWW Forward 0xE0 0x69 0xE0 0xE9
    WWWStop 123 WWW Stop 0xE0 0x68 0xE0 0xE8
    WWWRefresh 124 WWW Refrash 0xE0 0x67 0xE0 0xE7
    WWWFavorites 125 WWW Favorites 0xE0 0x66 0xE0 0xE6

     

    展开全文
  • keyboard scan code 表

    千次阅读 2013-08-22 08:08:55
    当按下一键时,产生 mark 码,产生一次 IRQ1 中断。 放开键时,产生 break 码,产生一次 IRQ1 中断。 因此:当按下 A 键放开,实际上产生了两次 IRQ1 中断 break 是 mark 码的 bit7 置 1 得来,也就是: break = ...

    当按下一键时,产生 mark 码,产生一次 IRQ1 中断。

    放开键时,产生 break 码,产生一次 IRQ1 中断。

    因此:当按下 A 键放开,实际上产生了两次 IRQ1 中断

    break 是 mark 码的 bit7 置 1 得来,也就是: break = mark + 0x80

     

    1、scan code 集

    这里只说一般日常应用中的键盘码集 set 2(有 set 1、set 2 以及 set 3)

    • 基本 scan code:绝大多数 scan code 是 1 byte 的。
    • 扩展 scan code:由 e0e1 或 e2 引导
    • 特殊的 PrintScreen/SysRq 键:e0 2a e0 37
    • 物殊的 Pause/Break 键:e1 1d 45 e1 9d c5

     

     

    2、小键盘 scan code 表

    key
    mark(Hex)
    break(Hex)
    描述
    NumLock
    45
    c5
    break = mark + 0x80
    /
    e0 35
    e0 b5
    由 e0 引导出 extend scan code
    *
    37
    b7
    break = mark + 0x80
    -
    4a
    ca
    同上
    7/Home
    47
    c7
    同上
    8/Up
    48
    c8
    同上
    9/PgUp
    49
    c9
    同上
    4/Left
    4b
    cb
    同上
    5
    4c
    cc
    同上
    6/Right
    4d
    cd
    同上
    1/End
    4f
    cf
    同上
    2/Down
    50
    d0
    同上
    3/PgDn
    51
    d1
    同上
    0/Ins
    52
    d2
    同上
    ./Del
    53
    d3
    同上
    +
    4e
    ce
    同上
    Enter
    e0 1c
    e0 9c
    extend scan code

    小键盘中的 <home><Up><PgUp><Left><Right><End><Down><PgDn><Ins><Del> 由 NumLock 按下后再按得来。

    因此,会产生一个 <NumLock> mark 码后,再产生上述的 mark 码。 释放 <NumLock> 又产生一个 break 码。

     

    3、附加键 scan code 表

    key
    mark(Hex)
    break(Hex)
    描述
    PrintScreen/SysRq
    e0 2a e0 37
    e0 b7 e0 aa
    extend scan code
    Scroll Lock
    46
    c6
    同上
    Pause/Break
    e1 1d 45 e1 9d c5
    *
    同上
    Insert
    e0 52
    e0 d2
    同上
    Home
    e0 47
    e0 c7
    同上
    Page Up
    e0 49
    e0 c9
    同上
    Delete
    e0 53
    e0 d3
    同上
    End
    e0 4f
    e0 cf
    同上
    Page Down
    e0 51
    e0 d1
    同上
    left
    e0 46
    e0 c6
    同上
    right
    e0 4d
    e0 cd
    同上
    up
    e0 48
    e0 c8
    同上
    down
    e0 50
    e0 d0
    同上

    抱歉:我对 PrintScreen/SysRq 和 Pause/Break 的理解未透彻。在这不便讲解。

    如果您知道,请留言赐教。

     

     

    4、功能键 scan code 表

    key
    mark(Hex)
    break(Hex)
    描述
    <esc>
    01
    81
    scan code
    F1
    3b
    bb
    同上
    F2
    3c
    bc
    同上
    F3
    3d
    bd
    同上
    F4
    3e
    be
    同上
    F5
    3f
    bf
    同上
    F6
    40
    c0
    同上
    F7
    41
    c1
    同上
    F8
    42
    c2
    同上
    F9
    43
    c3
    同上
    F10
    44
    c4
    同上
    F11
    57
    d7
    同上
    F12
    58
    d8
    同上

     

     

    5、主键盘 scan code 表

    key
    mark
    break
    key
    mark
    break
    key
    mark
    break
    key
    mark
    break
    ~/·
    29
    a9
    <tab>
    0f
    8f
    <scapslock>
    3a
    ba
    <L-shift>
    2a
    aa
    !/1
    02
    82
    q
    10
    90
    a
    1e
    9e
    z
    2c
    ac
    @/2
    03
    83
    w
    11
    91
    s
    1f
    9f
    x
    2d
    ad
    #/3
    04
    84
    e
    12
    12
    d
    20
    a0
    c
    2e
    ae
    $/4
    05
    85
    r
    13
    93
    f
    21
    a1
    v
    2f
    af
    %/5
    06
    86
    t
    14
    94
    g
    22
    a2
    b
    30
    b0
    ^/6
    07
    87
    y
    15
    95
    h
    23
    a3
    n
    31
    b1
    &/7
    08
    88
    u
    16
    96
    j
    24
    a4
    m
    32
    b2
    */8
    09
    89
    i
    17
    97
    k
    25
    a5
    </,
    33
    b3
    (/9
    0a
    8a
    o
    18
    98
    l
    26
    a6
    >/.
    34
    b4
    )/0
    0b
    8b
    p
    19
    99
    :/;
    27
    a7
    ?//
    35
    b5
    _/-
    0c
    8c
    {/[
    1a
    9a
    "/'
    28
    a8
    <R-shift>
    36
    b6
    +/=
    0d
    8d
    }/]
    1b
    9b
    <Enter>
    1c
    9c
    <L-ctrl>
    1d
    9d
    |/\
    2b
    ab
               
    <L-alt>
    38
    b8
    <backspace>
    0e
    8e
               
    <space>
    39
    b9
                     
    <R-alt>
    e0 38
    e0 b8
                     
    <R-ctrl>
    e0 1d
    e0 9d

    若输入字符“ABCD”有两种方法

    (1)按下 <CapsLock> 键后,再输入 abcd 键,再按 <CapsLock> 键

    这样会产生一个 <CapsLock> 键 mark 和 break 码,然后依次是 abcd 的 mark 和 break 码, 最后是 <CapsLock> 的 mark 和 break 码

     

    (2)按着 <L-shift> 或 <R-shift> 不放,再按 abcd 键,再放开 <L-shift> 或 <R-shift> 键

    这样会产生一个 <L-shift> 或 <R-shift> 键的 mark 码,然后依次是 abcd 的 mark 和 break 码,最后是一个 <L-shift> 或 <R-shift> 键的 break 码

    展开全文
  • ScanCode.rar

    2020-09-17 14:54:31
    扫一扫功能,精确扫描。使用了谷歌的zxing的jar包,进行了优化,扫一扫可以在0.2秒识别二维码上面的信息。大大提高了用户的体验。
  • Scancode到Keycode的映射

    2019-11-22 18:55:17
    getEvents读取设备节点的所有事件,通过parsekey方法解析kl文件存入数据结构map,在读取节点事件之前先扫描设备,如果没有打开则打开设备,在打开设备时会将scancode和keycode一一映射,此篇文章记录他们是如何建立...

    之前分析的InputReader读取底层事件可以得知 InputReaderThead启动之后会通过mEventHub->getEvents读取设备节点的所有事件,通过parsekey方法解析kl文件存入数据结构map,在读取节点事件之前先扫描设备,如果没有打开则打开设备,在打开设备时会将scancode和keycode一一映射,此篇文章记录他们是如何建立映射关系的起来的
    /frameworks/native/services/inputflinger/InputReader.cpp

    void InputReader::loopOnce() {
             ......
    343      size_t count = mEventHub->getEvents(timeoutMillis, mEventBuffer, EVENT_BUFFER_SIZE);
    344  
    345      { // acquire lock
    346          AutoMutex _l(mLock);
    347          mReaderIsAliveCondition.broadcast();
    348  
    349          if (count) {
    350              processEventsLocked(mEventBuffer, count);
    351          }
    352  
    

    /frameworks/native/services/inputflinger/EventHub.cpp
    mEventHub->getEvents

    851  size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) {
    852          ......
    860      bool awoken = false;
    861      for (;;) {
    862          nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
                 ......
    875          // Report any devices that had last been added/removed.
    876          while (mClosingDevices) {
    877              Device* device = mClosingDevices;
    878              ALOGV("Reporting device closed: id=%d, name=%s\n",
    879                   device->id, device->path.c_str());
    880          ......
    891          }
    892  
    893          if (mNeedToScanDevices) {
    894              mNeedToScanDevices = false;
    895              scanDevicesLocked();
    896              mNeedToSendFinishedDeviceScan = true;
    897          }
                 ......
       }
    

    /frameworks/native/services/inputflinger/EventHub.cpp
    扫描设备"/dev/input"

    static const char *DEVICE_PATH = "/dev/input";
    1130  void EventHub::scanDevicesLocked() {
              //DEVICE_PATH = "/dev/input"
    1131      status_t result = scanDirLocked(DEVICE_PATH);
    1132      ......
    1144  }
    
    1908  status_t EventHub::scanDirLocked(const char *dirname)
    1909  {
    1910      ......
              //扫描/dev/input/下的所有设备
    1920      while((de = readdir(dir))) {
    1921          if(de->d_name[0] == '.' &&
    1922             (de->d_name[1] == '\0' ||
    1923              (de->d_name[1] == '.' && de->d_name[2] == '\0')))
    1924              continue;
    1925          strcpy(filename, de->d_name);
                  //打开设备
    1926          openDeviceLocked(devname);
    1927      }
    1928      closedir(dir);
    1929      return 0;
    1930  }
    

    打开设备

    1237  status_t EventHub::openDeviceLocked(const char* devicePath) {
    1238        //省略了很多代码,主要看loadKeyMapLocked
    1258        ......
    1350        ......
    1429      // Load the key map.
    1430      // We need to do this for joysticks too because the key layout may specify axes.
    1431      status_t keyMapStatus = NAME_NOT_FOUND;
    1432      if (device->classes & (INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_JOYSTICK)) {
    1433          // Load the keymap for the device.
    1434          keyMapStatus = loadKeyMapLocked(device);
    1435      }
    }
    

    主要看scancode和keycode如何一一映射的

    1685  status_t EventHub::loadKeyMapLocked(Device* device) {
    1686      return device->keyMap.load(device->identifier, device->configuration);
    1687  }
    

    继续调到Device的keyMap的load函数,Device是EventHub内部的结构体
    /frameworks/native/services/inputflinger/EventHub.h

    325  private:
    326      struct Device {
    327          Device* next;
                 .......
    328          KeyMap keyMap;
                 .......
          }
    

    继续看KeyMap的load函数
    /frameworks/native/libs/input/Keyboard.cpp

    41  status_t KeyMap::load(const InputDeviceIdentifier& deviceIdenfifier,
    42          const PropertyMap* deviceConfiguration) {
    43      // Use the configured key layout if available.
    44      if (deviceConfiguration) {
    45          String8 keyLayoutName;
                //通过设备的配置文件去加载配置文件内制定好的映射表
    46          if (deviceConfiguration->tryGetProperty(String8("keyboard.layout"),
    47                  keyLayoutName)) {
    48              status_t status = loadKeyLayout(deviceIdenfifier, keyLayoutName.c_str());
    49           if (status == NAME_NOT_FOUND) {
    52                deviceIdenfifier.name.c_str(), keyLayoutName.string());
    53              }
    54          }
    55  
    56          String8 keyCharacterMapName;
    57          if (deviceConfiguration->tryGetProperty(String8("keyboard.characterMap"),
    58                  keyCharacterMapName)) {
    59              status_t status = loadKeyCharacterMap(deviceIdenfifier, keyCharacterMapName.c_str());
    60              if (status == NAME_NOT_FOUND) {
    61                  ALOGE("Configuration for keyboard device '%s' requested keyboard character "
    62                          "map '%s' but it was not found.",
    63                          deviceIdenfifier.name.c_str(), keyLayoutName.string());
    64              }
    65          }
    67          if (isComplete()) {
    68              return OK;
    69          }
    70      }
    72      // Try searching by device identifier.通过设备信息查找对应的映射表
    73      if (probeKeyMap(deviceIdenfifier, "")) {
    74          return OK;
    75      }
    77      // Fall back on the Generic key map.
    78      // TODO Apply some additional heuristics here to figure out what kind of
    79      //      generic key map to use (US English, etc.) for typical external keyboards.查找通用的映射表
    80      if (probeKeyMap(deviceIdenfifier, "Generic")) {
    81          return OK;
    82      }
    83  
    84      // Try the Virtual key map as a last resort.查找虚拟映射表
    85      if (probeKeyMap(deviceIdenfifier, "Virtual")) {
    86          return OK;
    87      }
    88  
    89      // Give up!
    90      ALOGE("Could not determine key map for device '%s' and no default key maps were found!",
    91              deviceIdenfifier.name.c_str());
    92      return NAME_NOT_FOUND;
    93  }
    

    可以看到我这个设备有四个设备节点,所以
    mtk-tpd,ACCDET,fts_ts,mtk-kpd以及通用表都会解析的

    Tokyo_TF:/system/usr $ getevent
    add device 1: /dev/input/event3
      name:     "mtk-tpd"
    add device 2: /dev/input/event0
      name:     "ACCDET"
    add device 3: /dev/input/event1
      name:     "mtk-kpd"
    add device 4: /dev/input/event2
      name:     "fts_ts"
    /dev/input/event1: 0001 0074 00000001
    /dev/input/event1: 0000 0000 00000000
    /dev/input/event1: 0001 0074 00000000
    /dev/input/event1: 0000 0000 00000000
    Tokyo_TF:/system/usr $ 
    Tokyo_TF:/system/usr $ find -name "mtk-kpd*"                                                                                             
    ./keylayout/mtk-kpd.kl
    Tokyo_TF:/system/usr $ 
    
    

    probeKeyMap函数

    95  bool KeyMap::probeKeyMap(const InputDeviceIdentifier& deviceIdentifier,
    96          const std::string& keyMapName) {
    97      if (!haveKeyLayout()) {
    98          loadKeyLayout(deviceIdentifier, keyMapName);
    99      }
    100      if (!haveKeyCharacterMap()) {
    101          loadKeyCharacterMap(deviceIdentifier, keyMapName);
    102      }
    103      return isComplete();
    104  }
    

    loadKeyLayout()函数

    106  status_t KeyMap::loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier,
    107          const std::string& name) {
    108      std::string path(getPath(deviceIdentifier, name,
    109              INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT));
    110      if (path.empty()) {
    111          return NAME_NOT_FOUND;
    112      }
    113  
    114      status_t status = KeyLayoutMap::load(path, &keyLayoutMap);
    115      if (status) {
    116          return status;
    117      }
    118  
    119      keyLayoutFile = path;
    120      return OK;
    121  }
    

    继续KeyLayoutMap::load
    /frameworks/native/libs/input/KeyLayoutMap.cpp

    52  status_t KeyLayoutMap::load(const std::string& filename, sp<KeyLayoutMap>* outMap) {
    54        ......
    55      Tokenizer* tokenizer;
    56      status_t status = Tokenizer::open(String8(filename.c_str()), &tokenizer);
    57      if (status) {
    58        ......
    59      } else {
    60          sp<KeyLayoutMap> map = new KeyLayoutMap();
    61          if (!map.get()) {
    62              ......
    64          } else {
    68              Parser parser(map.get(), tokenizer);
                    //解析map
    69              status = parser.parse();
    70              ......
    82      return status;
    83  }
    

    继续parser.parse(),开始解析映射表

    199  status_t KeyLayoutMap::Parser::parse() {
         //while循环,一行一行地解析映射表项
    200  while (!mTokenizer->isEof()) {
    201  #if DEBUG_PARSER
          /*
     11-22 04:27:06.719   908  1162 D KeyLayoutMap: Parsing /system/usr/keylayout/Generic.kl:160: '# key 138 "KEY_HELP"'.
    11-22 04:27:06.719   908  1162 D KeyLayoutMap: Parsing /system/usr/keylayout/Generic.kl:161: 'key 139   MENU'.
    11-22 04:27:06.719   908  1162 D KeyLayoutMap: Parsing /system/usr/keylayout/Generic.kl:151: '# key 129 "KEY_AGAIN"'.
    11-22 04:27:06.719   908  1162 D KeyLayoutMap: Parsing /system/usr/keylayout/Generic.kl:152: '# key 130 "KEY_PROPS"'.
    11-22 04:27:06.719   908  1162 D KeyLayoutMap: Parsing /system/usr/keylayout/Generic.kl:153: '# key 131 "KEY_UNDO"'.
    11-22 04:27:06.719   908  1162 D KeyLayoutMap: Parsing /system/usr/keylayout/Generic.kl:154: '# key 132 "KEY_FRONT"'.
        */
        //这条log的输入,部分
    202          ALOGD("Parsing %s: '%s'.", mTokenizer->getLocation().string(),
    203                  mTokenizer->peekRemainderOfLine().string());
    204  #endif
    206          mTokenizer->skipDelimiters(WHITESPACE);
    208          if (!mTokenizer->isEol() && mTokenizer->peekChar() != '#') {
    209              String8 keywordToken = mTokenizer->nextToken(WHITESPACE);
    210              if (keywordToken == "key") {
    211                  mTokenizer->skipDelimiters(WHITESPACE);
    212                  status_t status = parseKey();
    213                  if (status) return status;
    214              } else if (keywordToken == "axis") {
    215                  mTokenizer->skipDelimiters(WHITESPACE);
    216                  status_t status = parseAxis();
    217                  if (status) return status;
    218              } else if (keywordToken == "led") {
    219                  mTokenizer->skipDelimiters(WHITESPACE);
    220                  status_t status = parseLed();
    221                  if (status) return status;
    222              } else {
    223                  ALOGE("%s: Expected keyword, got '%s'.", mTokenizer->getLocation().string(),
    224                          keywordToken.string());
    225                  return BAD_VALUE;
    226              }
    227  
    228              mTokenizer->skipDelimiters(WHITESPACE);
    229              if (!mTokenizer->isEol() && mTokenizer->peekChar() != '#') {
    230                  ALOGE("%s: Expected end of line or trailing comment, got '%s'.",
    231                          mTokenizer->getLocation().string(),
    232                          mTokenizer->peekRemainderOfLine().string());
    233                  return BAD_VALUE;
    234              }
    235          }
    237          mTokenizer->nextLine();
    238      }
    239      return NO_ERROR;
    240  }
    

    mTokenizer->getLocation()这代表哪一张映射表,mTokenizer->peekRemainderOfLine()代表映射表中的scancode,
    解析的规则如下:
    keyword是"key",调用parseKey解析,如果解析出错则返回错误
    keyword是"axis",调用parseAxis解析,如果解析出错则返回错误
    keyword是"led",调用parseAxis解析,如果解析出错则返回错误
    如果还有其他不按规则的符号则返回BAD_VALUE

    继续parseKey()函数

    242  status_t KeyLayoutMap::Parser::parseKey() {
    243      ......
    256      //此函数解析得到keycode         
    267      int32_t keyCode = getKeyCodeByLabel(keyCodeToken.string());
    268      ......
         //11-22 04:55:50.301   852  1162 D KeyLayoutMap: Parsed key scan code: code=85, keyCode=211, flags=0x00000000.
    294  #if DEBUG_PARSER
    295      ALOGD("Parsed key %s: code=%d, keyCode=%d, flags=0x%08x.",
    296              mapUsage ? "usage" : "scan code", code, keyCode, flags);
    297  #endif
    298      Key key;
    299      key.keyCode = keyCode;
    300      key.flags = flags;
    301      map.add(code, key);
    302      return NO_ERROR;
    303  }
    

    打开上面的log开关得到如下输出:scancode和keycode的映射终于得到了,继续看函数getKeyCodeByLabel

    11-22 04:55:50.301   852  1162 D KeyLayoutMap: Parsed key scan code: code=83, keyCode=158, flags=0x00000000.
    11-22 04:55:50.301   852  1162 D KeyLayoutMap: Parsed key scan code: code=85, keyCode=211, flags=0x00000000.
    11-22 04:55:50.306   852  1162 D KeyLayoutMap: Parsed key scan code: code=173, keyCode=285, flags=0x00000000.
    11-22 04:55:50.316   852  1162 D KeyLayoutMap: Parsed key scan code: code=483, keyCode=47, flags=0x00000004.
    

    /frameworks/native/include/input/InputEventLabels.h

    434  static inline int32_t getKeyCodeByLabel(const char* label) {
    435      return int32_t(lookupValueByLabel(label, KEYCODES));
    436  }
    

    调用了lookupValueByLabel函数,我们来看 KEYCODES是什么,里面是所有的键

    23  #define DEFINE_KEYCODE(key) { #key, AKEYCODE_##key }
    39  static const InputEventLabel KEYCODES[] = {
    40      // NOTE: If you add a new keycode here you must also add it to several other files.
    41      //       Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
    44      ......  
    45      DEFINE_KEYCODE(HOME),
    46      DEFINE_KEYCODE(BACK),
    47      DEFINE_KEYCODE(CALL),
    48      DEFINE_KEYCODE(ENDCALL),
    49      DEFINE_KEYCODE(0),
    50      DEFINE_KEYCODE(1),
    51      DEFINE_KEYCODE(2),
    52      DEFINE_KEYCODE(3),
    53      DEFINE_KEYCODE(4),
    54      DEFINE_KEYCODE(5),
    55      DEFINE_KEYCODE(6),
    56      DEFINE_KEYCODE(7),
    57      DEFINE_KEYCODE(8),
    58      DEFINE_KEYCODE(9),
    59      DEFINE_KEYCODE(STAR),
    60      DEFINE_KEYCODE(POUND),
    61      DEFINE_KEYCODE(DPAD_UP),
    62      DEFINE_KEYCODE(DPAD_DOWN),
    63      DEFINE_KEYCODE(DPAD_LEFT),
    64      DEFINE_KEYCODE(DPAD_RIGHT),
    65      DEFINE_KEYCODE(DPAD_CENTER),
    66      DEFINE_KEYCODE(VOLUME_UP),
    67      DEFINE_KEYCODE(VOLUME_DOWN),
    68      DEFINE_KEYCODE(POWER),
    69      DEFINE_KEYCODE(CAMERA),
    70      DEFINE_KEYCODE(CLEAR),
            ......
    

    DEFINE_KEYCODE这个宏定义作用是将传进去的键名称拼接为AKEYCODE_XXX,比如我们传一个POWER进去得到的就是{ “POWER”, AKEYCODE_POWER }

    而AKEYCODE_POWER,我们全局搜索一下,可以发现定义在
    /frameworks/native/include/android/keycodes.h

    51  /**
    52   * Key codes.
    53   */
    54  enum {
    55      /** Unknown key code. */
    56      AKEYCODE_UNKNOWN         = 0,
    57      /** Soft Left key.
    58       * Usually situated below the display on phones and used as a multi-function
    59       * feature key for selecting a software defined function shown on the bottom left
    60       * of the display. */
    61      AKEYCODE_SOFT_LEFT       = 1,
    62      /** Soft Right key.
    63       * Usually situated below the display on phones and used as a multi-function
    64       * feature key for selecting a software defined function shown on the bottom right
    65       * of the display. */
    66      AKEYCODE_SOFT_RIGHT      = 2,
    67      /** Home key.
    68       * This key is handled by the framework and is never delivered to applications. */
    69      AKEYCODE_HOME            = 3,
    70      /** Back key. */
    71      AKEYCODE_BACK            = 4,
    72      /** Call key. */
    73      AKEYCODE_CALL            = 5,
    74      /** End Call key. */
    75      AKEYCODE_ENDCALL         = 6,
    76      /** '0' key. */
    77      AKEYCODE_0               = 7,
    78      /** '1' key. */
    79      AKEYCODE_1               = 8,
    80      /** '2' key. */
    81      AKEYCODE_2               = 9,
    82      /** '3' key. */
    83      AKEYCODE_3               = 10,
    84      /** '4' key. */
    85      AKEYCODE_4               = 11,
    86      /** '5' key. */
    87      AKEYCODE_5               = 12,
    88      /** '6' key. */
    89      AKEYCODE_6               = 13,
    90      /** '7' key. */
    91      AKEYCODE_7               = 14,
    92      /** '8' key. */
    93      AKEYCODE_8               = 15,
    94      /** '9' key. */
    95      AKEYCODE_9               = 16,
    96      /** '*' key. */
    97      AKEYCODE_STAR            = 17,
    98      /** '#' key. */
    99      AKEYCODE_POUND           = 18,
    100      /** Directional Pad Up key.
    101       * May also be synthesized from trackball motions. */
    102      AKEYCODE_DPAD_UP         = 19,
    103      /** Directional Pad Down key.
    104       * May also be synthesized from trackball motions. */
    105      AKEYCODE_DPAD_DOWN       = 20,
    106      /** Directional Pad Left key.
    107       * May also be synthesized from trackball motions. */
    108      AKEYCODE_DPAD_LEFT       = 21,
    109      /** Directional Pad Right key.
    110       * May also be synthesized from trackball motions. */
    111      AKEYCODE_DPAD_RIGHT      = 22,
    112      /** Directional Pad Center key.
    113       * May also be synthesized from trackball motions. */
    114      AKEYCODE_DPAD_CENTER     = 23,
    115      /** Volume Up key.
    116       * Adjusts the speaker volume up. */
    117      AKEYCODE_VOLUME_UP       = 24,
    118      /** Volume Down key.
    119       * Adjusts the speaker volume down. */
    120      AKEYCODE_VOLUME_DOWN     = 25,
    121      /** Power key. */
    122      AKEYCODE_POWER           = 26,
             ......
      }
    

    并且在java层也是用的映射的keycode,这都是和native层一致的
    frameworks/base/core/java/android/view/KeyEvent.java

    88  public class KeyEvent extends InputEvent implements Parcelable {
    89      /** Key code constant: Unknown key code. */
    90      public static final int KEYCODE_UNKNOWN         = 0;
    91      /** Key code constant: Soft Left key.
    92       * Usually situated below the display on phones and used as a multi-function
    93       * feature key for selecting a software defined function shown on the bottom left
    94       * of the display. */
    95      public static final int KEYCODE_SOFT_LEFT       = 1;
    96      /** Key code constant: Soft Right key.
    97       * Usually situated below the display on phones and used as a multi-function
    98       * feature key for selecting a software defined function shown on the bottom right
    99       * of the display. */
    100      public static final int KEYCODE_SOFT_RIGHT      = 2;
    101      /** Key code constant: Home key.
    102       * This key is handled by the framework and is never delivered to applications. */
    103      public static final int KEYCODE_HOME            = 3;
    104      /** Key code constant: Back key. */
    105      public static final int KEYCODE_BACK            = 4;
    106      /** Key code constant: Call key. */
    107      public static final int KEYCODE_CALL            = 5;
    108      /** Key code constant: End Call key. */
    109      public static final int KEYCODE_ENDCALL         = 6;
    110      /** Key code constant: '0' key. */
    111      public static final int KEYCODE_0               = 7;
    112      /** Key code constant: '1' key. */
    113      public static final int KEYCODE_1               = 8;
    114      /** Key code constant: '2' key. */
    115      public static final int KEYCODE_2               = 9;
    116      /** Key code constant: '3' key. */
    117      public static final int KEYCODE_3               = 10;
    118      /** Key code constant: '4' key. */
    119      public static final int KEYCODE_4               = 11;
    120      /** Key code constant: '5' key. */
    121      public static final int KEYCODE_5               = 12;
    122      /** Key code constant: '6' key. */
    123      public static final int KEYCODE_6               = 13;
    124      /** Key code constant: '7' key. */
    125      public static final int KEYCODE_7               = 14;
    126      /** Key code constant: '8' key. */
    127      public static final int KEYCODE_8               = 15;
    128      /** Key code constant: '9' key. */
    129      public static final int KEYCODE_9               = 16;
    130      /** Key code constant: '*' key. */
    131      public static final int KEYCODE_STAR            = 17;
    132      /** Key code constant: '#' key. */
    133      public static final int KEYCODE_POUND           = 18;
    134      /** Key code constant: Directional Pad Up key.
    135       * May also be synthesized from trackball motions. */
    136      public static final int KEYCODE_DPAD_UP         = 19;
    137      /** Key code constant: Directional Pad Down key.
    138       * May also be synthesized from trackball motions. */
    139      public static final int KEYCODE_DPAD_DOWN       = 20;
    140      /** Key code constant: Directional Pad Left key.
    141       * May also be synthesized from trackball motions. */
    142      public static final int KEYCODE_DPAD_LEFT       = 21;
    143      /** Key code constant: Directional Pad Right key.
    144       * May also be synthesized from trackball motions. */
    145      public static final int KEYCODE_DPAD_RIGHT      = 22;
    146      /** Key code constant: Directional Pad Center key.
    147       * May also be synthesized from trackball motions. */
    148      public static final int KEYCODE_DPAD_CENTER     = 23;
    149      /** Key code constant: Volume Up key.
    150       * Adjusts the speaker volume up. */
    151      public static final int KEYCODE_VOLUME_UP       = 24;
    152      /** Key code constant: Volume Down key.
    153       * Adjusts the speaker volume down. */
    154      public static final int KEYCODE_VOLUME_DOWN     = 25;
    155      /** Key code constant: Power key. */
    156      public static final int KEYCODE_POWER           = 26;
             ......
    }
    

    到这里scancode与keycode的映射就创建完成,
    用一个实际例子来总结一下映射关系

    Tokyo_TF:/ $ getevent
    add device 1: /dev/input/event3
      name:     "mtk-tpd"
    add device 2: /dev/input/event0
      name:     "ACCDET"
    add device 3: /dev/input/event1
      name:     "mtk-kpd"
    add device 4: /dev/input/event2
      name:     "fts_ts"
    /dev/input/event1: 0001 0074 00000001
    /dev/input/event1: 0000 0000 00000000
    /dev/input/event1: 0001 0074 00000000
    /dev/input/event1: 0000 0000 00000000
    Tokyo_TF:/ $ cat system/usr/keylayout/mtk-kpd.kl |grep -i POWER                                                                      
    key 116   POWER
    
    

    16进制74对应10进制116,按键名称POWER,经过scancode到keycode的映射,POWER事件传到native层变为了AKEYCODE_POWER,到java层变为了KEYCODE_POWER,keycode都一样等于26,到此底层对上层事件的映射就已经完成,之后会接着InputReader读取设备事件,分析InputDispatcher是如何将事件给到应用窗口的。

    展开全文
  • 键盘扫描码对照表(scancode),详细的键盘扫描码对照表及相关说明。
  • 效果jslet app = getApp(); Page({ data: { img: "/images/1.jpg" }, onLoad() { ... wx.scanCode({ success: (res) =&gt; { console.log("扫码结果"); console.log(res)...
  • Scan code 在windows上的简单经验简单记录 简单记录 ...文档维护的有问题, 所以我们自己记录一下 下载解压 下载的时候, 不要跟着wiki文档的链接去下载, 从首页的last release进去就好 我没细看, 好像开始支持python3了...
  • 在业务中遇到需要获取商品的二维码的信息返回商品的二维码信息,在调用后台的接口,首先想到用小程序的Api,wx.scanCode(Object object)获取二维码信息。 支持相机扫描或者相册获取二维码。 getScancode: ...
  • 【键盘的构造及历史】 对于键盘,如果想要表示某个按键,硬件上对应着某个点,有两种方法,一种是对于每个按键,都设计一个硬件的点,另外一种是设计成矩阵式,即由多少行,多少列所组成。...
  • Scancode Map 自定义Keyboard

    千次阅读 2013-10-24 12:29:20
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout中添加Scancode Map 二进制内容 YUAN 0000 00 00 00 00 00 00 00 00 0008 03 00 00 00 3A 00 1D 00 0010 1D 00 3A 00 00 00 00 00 0018 ...
  • 微信小程序wx.scanCode扫码之坑

    万次阅读 2018-09-12 14:22:05
    最近做了一个小程序, 使用wx.scanCode这个Api扫描微信小程序生成的二维码,发现在微信开发者工具和真机使用的参数不一样,这需要在微信里打开调试,查看从二维码获取参数到的参数,下面分别是微信开发者工具和真机...
  • (1)“Scancode Map”是注册表中 [HKEY_LOCAL_MacHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]中的一个二进制键值(默认没有,需新建),并且有固定的格式。 Scancode Map 代码的一般格式是: ...
  • uni.scanCode 扫码问题

    千次阅读 2019-05-27 16:06:00
    <template> <view> <view class="page-body"> <view class="page-section-title">扫码结果</view> <view class="uni-list"> ...
  • 调起客户端扫码界面,扫码成功后返回对应的结果 Object 参数说明: 参数 类型 必填 说明 最低版本 onlyFromCamera ... 是否只能从相机扫码,不允许从相册选择图片 ... 扫码类型,参数类型是数组,...
  • 目前分享真机无效,开放工具可用. **注意:(2017.2.12更新) 最近几天有很多同学问我扫描失败的问题.这里说明一下,没有appid,在开发工具和真机上会一直扫描失败.** 微信小程序开发之页面分享 onShareAppMessage 扫码...
  • Java词法分析器 实现篇

    千次阅读 2010-07-19 00:16:00
    由于还有一些同学没有做完这个实验,为了不让大家产生不该有的误会,所以实现代码7月以后再贴出来与大家分享!先贴图敬请期待!
  • 目前分享真机无效,开放工具可用.  微信小程序开发之页面分享 onShareAppMessage  扫码真机,开发工具均可用.... ...仔细读了一遍文档,这个API只是调起了客户端扫码界面,扫码成功后返回对应的结果....
  • windows xp 注册表 修改键盘映射

    万次阅读 2011-11-23 23:50:50
    windows修改注册表键盘映射是通过添加 Scancode Map项来达到映射的目的的。 Scancode Map的路径为 : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout 新建时选择 "二进制值", 名为: ...
  • !... 42后面的参数是我在ScanResult后面拼接的,但在我跳转的方法用request.getParameter("activityID");只能获取到42 ,后面的获取不到,**_麻烦各路大神回答_**,请各位路过的兄弟姐妹们帮忙顶一下,谢谢大家了
1 2 3 4 5 ... 20
收藏数 5,680
精华内容 2,272
关键字:

scancode