Annotation of ntddk/src/input/kbdus/kbdus.c, revision 1.1.1.1

1.1       root        1: /***************************************************************************\
                      2: * Module Name: kbdus.c
                      3: *
                      4: * Copyright (c) 1985-93, Microsoft Corporation
                      5: *
                      6: * History:
                      7: \***************************************************************************/
                      8: 
                      9: #include <windows.h>
                     10: #include "vkoem.h"
                     11: #include "kbd.h"
                     12: #include "kbdus.h"
                     13: 
                     14: /***************************************************************************\
                     15: * asuVK[] - Virtual Scan Code to Virtual Key conversion table for US
                     16: \***************************************************************************/
                     17: 
                     18: static USHORT ausVK[] = {
                     19:     T00, T01, T02, T03, T04, T05, T06, T07,
                     20:     T08, T09, T0A, T0B, T0C, T0D, T0E, T0F,
                     21:     T10, T11, T12, T13, T14, T15, T16, T17,
                     22:     T18, T19, T1A, T1B, T1C, T1D, T1E, T1F,
                     23:     T20, T21, T22, T23, T24, T25, T26, T27,
                     24:     T28, T29, T2A, T2B, T2C, T2D, T2E, T2F,
                     25:     T30, T31, T32, T33, T34, T35,
                     26: 
                     27:     /* 
                     28:      * Right-hand Shift key must have KBDEXT bit set.
                     29:      */
                     30:     T36 | KBDEXT,
                     31: 
                     32:     T37 | KBDMULTIVK,               // numpad_* + Shift/Alt -> SnapShot
                     33: 
                     34:     T38, T39, T3A, T3B, T3C, T3D, T3E,
                     35:     T3F, T40, T41, T42, T43, T44,
                     36: 
                     37:     /*
                     38:      * NumLock Key:
                     39:      *     KBDEXT     - VK_NUMLOCK is an Extended key
                     40:      *     KBDMULTIVK - VK_NUMLOCK or VK_PAUSE (without or with CTRL)
                     41:      */
                     42:     T45 | KBDEXT | KBDMULTIVK,
                     43: 
                     44:     T46 | KBDMULTIVK,
                     45: 
                     46:     /*
                     47:      * Number Pad keys:
                     48:      *     KBDNUMPAD  - digits 0-9 and decimal point.
                     49:      *     KBDSPECIAL - require special processing by Windows
                     50:      */
                     51:     T47 | KBDNUMPAD | KBDSPECIAL,   // Numpad 7 (Home)
                     52:     T48 | KBDNUMPAD | KBDSPECIAL,   // Numpad 8 (Up),
                     53:     T49 | KBDNUMPAD | KBDSPECIAL,   // Numpad 9 (PgUp),
                     54:     T4A,
                     55:     T4B | KBDNUMPAD | KBDSPECIAL,   // Numpad 4 (Left),
                     56:     T4C | KBDNUMPAD | KBDSPECIAL,   // Numpad 5 (Clear),
                     57:     T4D | KBDNUMPAD | KBDSPECIAL,   // Numpad 6 (Right),
                     58:     T4E,
                     59:     T4F | KBDNUMPAD | KBDSPECIAL,   // Numpad 1 (End),
                     60:     T50 | KBDNUMPAD | KBDSPECIAL,   // Numpad 2 (Down),
                     61:     T51 | KBDNUMPAD | KBDSPECIAL,   // Numpad 3 (PgDn),
                     62:     T52 | KBDNUMPAD | KBDSPECIAL,   // Numpad 0 (Ins),
                     63:     T53 | KBDNUMPAD | KBDSPECIAL,   // Numpad . (Del),
                     64: 
                     65:     T54, T55, T56, T57, T58, T59, T5A, T5B,
                     66:     T5C, T5D, T5E, T5F, T60, T61, T62, T63,
                     67:     T64, T65, T66, T67, T68, T69, T6A, T6B,
                     68:     T6C, T6D, T6E, T6F, T70, T71, T72, T73,
                     69:     T74, T75, T76, T77, T78, T79, T7A, T7B,
                     70:     T7C
                     71: 
                     72: };
                     73: 
                     74: static VSC_VK aE0VscToVk[] = {
                     75:         { 0x1C, X1C | KBDEXT              },  // Numpad Enter
                     76:         { 0x1D, X1D | KBDEXT              },  // RControl
                     77:         { 0x35, X35 | KBDEXT              },  // Numpad Divide
                     78:         { 0x37, X37 | KBDEXT              },  // Snapshot
                     79:         { 0x38, X38 | KBDEXT              },  // RMenu
                     80:         { 0x46, X46 | KBDEXT              },  // Break (Ctrl + Pause)
                     81:         { 0x47, X47 | KBDEXT              },  // Home
                     82:         { 0x48, X48 | KBDEXT              },  // Up
                     83:         { 0x49, X49 | KBDEXT              },  // Prior
                     84:         { 0x4B, X4B | KBDEXT              },  // Left
                     85:         { 0x4D, X4D | KBDEXT              },  // Right
                     86:         { 0x4F, X4F | KBDEXT              },  // End
                     87:         { 0x50, X50 | KBDEXT              },  // Down
                     88:         { 0x51, X51 | KBDEXT              },  // Next
                     89:         { 0x52, X52 | KBDEXT              },  // Insert
                     90:         { 0x53, X53 | KBDEXT              },  // Delete
                     91:         { 0,      0                       }
                     92: };
                     93: 
                     94: static VSC_VK aE1VscToVk[] = {
                     95:         { 0x1D, Y1D                       },  // Pause
                     96:         { 0   ,   0                       }
                     97: };
                     98: 
                     99: /***************************************************************************\
                    100: * aVkToBits[]  - map Virtual Keys to Modifier Bits
                    101: *
                    102: * See kbd.h for a full description.
                    103: *
                    104: * US Keyboard has only three shifter keys:
                    105: *     SHIFT (L & R) affects alphabnumeric keys,
                    106: *     CTRL  (L & R) is used to generate control characters
                    107: *     ALT   (L & R) used for generating characters by number with numpad
                    108: \***************************************************************************/
                    109: 
                    110: static VK_TO_BIT aVkToBits[] = {
                    111:     { VK_SHIFT,   KBDSHIFT },
                    112:     { VK_CONTROL, KBDCTRL  },
                    113:     { VK_MENU,    KBDALT   },
                    114:     { 0,          0        }
                    115: };
                    116: 
                    117: /***************************************************************************\
                    118: * aModification[]  - map character modifier bits to modification number
                    119: *
                    120: * See kbd.h for a full description.
                    121: *
                    122: \***************************************************************************/
                    123: 
                    124: static MODIFIERS CharModifiers = {
                    125:     &aVkToBits[0],
                    126:     3,
                    127:     {
                    128:     //  Modification# //  Keys Pressed  : Explanation
                    129:     //  ============= // ============== : =============================
                    130:         0,            //                : unshifted characters
                    131:         1,            //          SHIFT : capitals, ~!@#$%^&*()_+{}:"<>? etc.
                    132:         2,            //     CTRL       : control characters
                    133:         3             //     CTRL SHIFT :
                    134:                       // ALT            : invalid
                    135:                       // ALT      SHIFT : invalid
                    136:                       // ALT CTRL       : invalid
                    137:                       // ALT CTRL SHIFT : invalid
                    138:     }
                    139: };
                    140: 
                    141: /***************************************************************************\
                    142: *
                    143: * aVkToWch2[]  - Virtual Key to WCHAR translation for 2 shift states
                    144: * aVkToWch3[]  - Virtual Key to WCHAR translation for 3 shift states
                    145: * aVkToWch4[]  - Virtual Key to WCHAR translation for 4 shift states
                    146: *
                    147: * Table attributes: Unordered Scan, null-terminated
                    148: *
                    149: * Search this table for an entry with a matching Virtual Key to find the
                    150: * corresponding unshifted and shifted WCHAR characters.
                    151: *
                    152: * Reserved VirtualKey values (first column)
                    153: *     -1            - this line contains dead characters (diacritic)
                    154: *     0             - terminator
                    155: *
                    156: * Reserved Attribute values (second column)
                    157: *     CAPLOK        - CapsLock affects this key like Shift
                    158: *
                    159: * Reserved character values (third through last column)
                    160: *     WCH_NONE      - No character
                    161: *     WCH_DEAD      - Dead character (diacritic) value is in next line
                    162: *
                    163: \***************************************************************************/
                    164: 
                    165: static VK_TO_WCHARS2 aVkToWch2[] = {
                    166:     {'0'          , 0      ,'0'       ,')'       },
                    167:     {'1'          , 0      ,'1'       ,'!'       },
                    168:     {'3'          , 0      ,'3'       ,'#'       },
                    169:     {'4'          , 0      ,'4'       ,'$'       },
                    170:     {'5'          , 0      ,'5'       ,'%'       },
                    171:     {'7'          , 0      ,'7'       ,'&'       },
                    172:     {'8'          , 0      ,'8'       ,'*'       },
                    173:     {'9'          , 0      ,'9'       ,'('       },
                    174:     {'A'          , CAPLOK ,'a'       ,'A'       },
                    175:     {'B'          , CAPLOK ,'b'       ,'B'       },
                    176:     {'C'          , CAPLOK ,'c'       ,'C'       },
                    177:     {'D'          , CAPLOK ,'d'       ,'D'       },
                    178:     {'E'          , CAPLOK ,'e'       ,'E'       },
                    179:     {'F'          , CAPLOK ,'f'       ,'F'       },
                    180:     {'G'          , CAPLOK ,'g'       ,'G'       },
                    181:     {'H'          , CAPLOK ,'h'       ,'H'       },
                    182:     {'I'          , CAPLOK ,'i'       ,'I'       },
                    183:     {'J'          , CAPLOK ,'j'       ,'J'       },
                    184:     {'K'          , CAPLOK ,'k'       ,'K'       },
                    185:     {'L'          , CAPLOK ,'l'       ,'L'       },
                    186:     {'M'          , CAPLOK ,'m'       ,'M'       },
                    187:     {'N'          , CAPLOK ,'n'       ,'N'       },
                    188:     {'O'          , CAPLOK ,'o'       ,'O'       },
                    189:     {'P'          , CAPLOK ,'p'       ,'P'       },
                    190:     {'Q'          , CAPLOK ,'q'       ,'Q'       },
                    191:     {'R'          , CAPLOK ,'r'       ,'R'       },
                    192:     {'S'          , CAPLOK ,'s'       ,'S'       },
                    193:     {'T'          , CAPLOK ,'t'       ,'T'       },
                    194:     {'U'          , CAPLOK ,'u'       ,'U'       },
                    195:     {'V'          , CAPLOK ,'v'       ,'V'       },
                    196:     {'W'          , CAPLOK ,'w'       ,'W'       },
                    197:     {'X'          , CAPLOK ,'x'       ,'X'       },
                    198:     {'Y'          , CAPLOK ,'y'       ,'Y'       },
                    199:     {'Z'          , CAPLOK ,'z'       ,'Z'       },
                    200:     {VK_OEM_1     , 0      ,';'       ,':'       },
                    201:     {VK_OEM_2     , 0      ,'/'       ,'?'       },
                    202:     {VK_OEM_3     , 0      ,'`'       ,'~'       },
                    203:     {VK_OEM_7     , 0      ,0x27      ,'"'       },
                    204:     {VK_OEM_8     , 0      ,WCH_NONE  ,WCH_NONE  },
                    205:     {VK_OEM_COMMA , 0      ,','       ,'<'       },
                    206:     {VK_OEM_PERIOD, 0      ,'.'       ,'>'       },
                    207:     {VK_OEM_PLUS  , 0      ,'='       ,'+'       },
                    208:     {VK_TAB       , 0      ,'\t'      ,'\t'      },
                    209:     {VK_ADD       , 0      ,'+'       ,'+'       },
                    210:     {VK_DECIMAL   , 0      ,'.'       ,'.'       },
                    211:     {VK_DIVIDE    , 0      ,'/'       ,'/'       },
                    212:     {VK_MULTIPLY  , 0      ,'*'       ,'*'       },
                    213:     {VK_SUBTRACT  , 0      ,'-'       ,'-'       },
                    214:     {0            , 0      ,0         ,0         }
                    215: };
                    216: 
                    217: static VK_TO_WCHARS3 aVkToWch3[] = {
                    218:     //                     |          |   SHIFT  |  CONTROL  |
                    219:     //                     |          |==========|===========|
                    220:     {VK_BACK      , 0      ,'\b'      ,'\b'      , 0x7f      },
                    221:     {VK_CANCEL    , 0      ,0x03      ,0x03      , 0x03      },
                    222:     {VK_ESCAPE    , 0      ,0x1b      ,0x1b      , 0x1b      },
                    223:     {VK_OEM_4     , 0      ,'['       ,'{'       , 0x1b      },
                    224:     {VK_OEM_5     , 0      ,'\\'      ,'|'       , 0x1c      },
                    225:     {VK_OEM_102   , 0      ,'\\'      ,'|'       , 0x1c      },
                    226:     {VK_OEM_6     , 0      ,']'       ,'}'       , 0x1d      },
                    227:     {VK_RETURN    , 0      ,'\r'      ,'\r'      , '\n'      },
                    228:     {VK_SPACE     , 0      ,' '       ,' '       , 0x20      },
                    229:     {0            , 0      ,0         ,0         , 0         }
                    230: };
                    231: 
                    232: static VK_TO_WCHARS4 aVkToWch4[] = {
                    233:     //                     |          |   SHIFT  |  CONTROL  | SHFT+CTRL |
                    234:     //                     |          |==========|===========|===========|
                    235:     {'2'          , 0      ,'2'       ,'@'       , WCH_NONE  , 0x00      },
                    236:     {'6'          , 0      ,'6'       ,'^'       , WCH_NONE  , 0x1e      },
                    237:     {VK_OEM_MINUS , 0      ,'-'       ,'_'       , WCH_NONE  , 0x1f      },
                    238:     {0            , 0      ,0         ,0         , 0         , 0         }
                    239: };
                    240: 
                    241: // Put this last so that VkKeyScan interprets number characters
                    242: // as coming from the main section of the kbd (aVkToWch2 and
                    243: // aVkToWch4) before considering the numpad (aVkToWch1).
                    244: 
                    245: static VK_TO_WCHARS1 aVkToWch1[] = {
                    246:     { VK_NUMPAD0   , 0      ,  '0'   },
                    247:     { VK_NUMPAD1   , 0      ,  '1'   },
                    248:     { VK_NUMPAD2   , 0      ,  '2'   },
                    249:     { VK_NUMPAD3   , 0      ,  '3'   },
                    250:     { VK_NUMPAD4   , 0      ,  '4'   },
                    251:     { VK_NUMPAD5   , 0      ,  '5'   },
                    252:     { VK_NUMPAD6   , 0      ,  '6'   },
                    253:     { VK_NUMPAD7   , 0      ,  '7'   },
                    254:     { VK_NUMPAD8   , 0      ,  '8'   },
                    255:     { VK_NUMPAD9   , 0      ,  '9'   },
                    256:     { 0            , 0      ,  '\0'  }   //null terminator
                    257: };
                    258: 
                    259: /***************************************************************************\
                    260: * aVkToWcharTable: table of pointers to Character Tables
                    261: *
                    262: * Describes the character tables and the order they should be searched.
                    263: *
                    264: * Note: the order determines the behavior of VkKeyScan() : this function
                    265: *       takes a character and attempts to find a Virtual Key and character-
                    266: *       modifier key combination that produces that character.  The table
                    267: *       containing the numeric keypad (aVkToWch1) must appear last so that
                    268: *       VkKeyScan('0') will be interpreted as one of keys from the main
                    269: *       section, not the numpad.  etc.
                    270: \***************************************************************************/
                    271: 
                    272: static VK_TO_WCHAR_TABLE aVkToWcharTable[] = {
                    273:     {  (PVK_TO_WCHARS1)aVkToWch3, 3, sizeof(aVkToWch3[0]) },
                    274:     {  (PVK_TO_WCHARS1)aVkToWch4, 4, sizeof(aVkToWch4[0]) },
                    275:     {  (PVK_TO_WCHARS1)aVkToWch2, 2, sizeof(aVkToWch2[0]) },
                    276:     {  (PVK_TO_WCHARS1)aVkToWch1, 1, sizeof(aVkToWch1[0]) },  // must come last
                    277:     {                       NULL, 0, 0                    }
                    278: };
                    279: 
                    280: /***************************************************************************\
                    281: * aKeyNames[], aKeyNamesExt[]  - Scan Code -> Key Name tables
                    282: *
                    283: * For the GetKeyNameText() API function
                    284: *
                    285: * Tables for non-extended and extended (KBDEXT) keys.
                    286: * (Keys producing printable characters are named by the character itself)
                    287: \***************************************************************************/
                    288: 
                    289: static VSC_LPWSTR aKeyNames[] = {
                    290:     0x01,    L"Esc",
                    291:     0x0e,    L"Backspace",
                    292:     0x0f,    L"Tab",
                    293:     0x1c,    L"Enter",
                    294:     0x1d,    L"Ctrl",
                    295:     0x2a,    L"Shift",
                    296:     0x36,    L"Right Shift",
                    297:     0x37,    L"Num *",
                    298:     0x38,    L"Alt",
                    299:     0x39,    L"Space",
                    300:     0x3a,    L"Caps Lock",
                    301:     0x3b,    L"F1",
                    302:     0x3c,    L"F2",
                    303:     0x3d,    L"F3",
                    304:     0x3e,    L"F4",
                    305:     0x3f,    L"F5",
                    306:     0x40,    L"F6",
                    307:     0x41,    L"F7",
                    308:     0x42,    L"F8",
                    309:     0x43,    L"F9",
                    310:     0x44,    L"F10",
                    311:     0x45,    L"Pause",
                    312:     0x46,    L"Scroll Lock",
                    313:     0x47,    L"Num 7",
                    314:     0x48,    L"Num 8",
                    315:     0x49,    L"Num 9",
                    316:     0x4a,    L"Num -",
                    317:     0x4b,    L"Num 4",
                    318:     0x4c,    L"Num 5",
                    319:     0x4d,    L"Num 6",
                    320:     0x4e,    L"Num +",
                    321:     0x4f,    L"Num 1",
                    322:     0x50,    L"Num 2",
                    323:     0x51,    L"Num 3",
                    324:     0x52,    L"Num 0",
                    325:     0x53,    L"Num Del",
                    326:     0x54,    L"Sys Req",
                    327:     0x57,    L"F11",
                    328:     0x58,    L"F12",
                    329:     0x7C,    L"F13",
                    330:     0x7D,    L"F14",
                    331:     0x7E,    L"F15",
                    332:     0x7F,    L"F16",
                    333:     0x80,    L"F17",
                    334:     0x81,    L"F18",
                    335:     0x82,    L"F19",
                    336:     0x83,    L"F20",
                    337:     0x84,    L"F21",
                    338:     0x85,    L"F22",
                    339:     0x86,    L"F23",
                    340:     0x87,    L"F24",
                    341:     0   ,    NULL
                    342: };
                    343: 
                    344: static VSC_LPWSTR aKeyNamesExt[] = {
                    345:     0x1c,    L"Num Enter",
                    346:     0x1d,    L"Right Control",
                    347:     0x35,    L"Num /",
                    348:     0x37,    L"Prnt Scrn",
                    349:     0x38,    L"Right Alt",
                    350:     0x45,    L"Num Lock",
                    351:     0x46,    L"Break",
                    352:     0x47,    L"Home",
                    353:     0x48,    L"Up",
                    354:     0x49,    L"Page Up",
                    355:     0x4b,    L"Left",
                    356:     0x4d,    L"Right",
                    357:     0x4f,    L"End",
                    358:     0x50,    L"Down",
                    359:     0x51,    L"Page Down",
                    360:     0x52,    L"Insert",
                    361:     0x53,    L"Delete",
                    362:     0x54,    L"<00>",
                    363:     0x56,    L"Help",
                    364:     0x5C,    L"Clear",
                    365:     0   ,    NULL
                    366: };
                    367: 
                    368: static KBDTABLES KbdTables = {
                    369:     /*
                    370:      * Modifier keys
                    371:      */
                    372:     &CharModifiers,
                    373: 
                    374:     /*
                    375:      * Characters tables
                    376:      */
                    377:     aVkToWcharTable,
                    378: 
                    379:     /*
                    380:      * Diacritics  (none for US English)
                    381:      */
                    382:     NULL,
                    383: 
                    384:     /*
                    385:      * Names of Keys  (no dead keys)
                    386:      */
                    387:     aKeyNames,
                    388:     aKeyNamesExt,
                    389:     NULL,
                    390: 
                    391:     /*
                    392:      * Scan codes to Virtual Keys
                    393:      */
                    394:     ausVK,
                    395:     sizeof(ausVK) / sizeof(ausVK[0]),
                    396:     aE0VscToVk,
                    397:     aE1VscToVk,
                    398: 
                    399:     /*
                    400:      * No Locale-specific special processing
                    401:      */
                    402:     0
                    403: };
                    404: 
                    405: PKBDTABLES KbdLayerDescriptor(VOID)
                    406: {
                    407:     return &KbdTables;
                    408: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.