![]() |
ZenWINX Architecture - Reference Manual - Guides |
|
00001 /* 00002 * ReactOS kernel 00003 * Copyright (C) 2002 ReactOS Team 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 /* 00021 * COPYRIGHT: LGPL 00022 * PROJECT: ReactOS text-mode setup 00023 * FILE: subsys/system/usetup/keytrans.c 00024 * PURPOSE: Console support functions: keyboard translation 00025 * PROGRAMMER: Tinus 00026 * 00027 * NB: Hardcoded to US keyboard 00028 */ 00029 00030 /* Modified by Dmitri Arkhangelski, 2007. */ 00031 00039 #include "ntndk.h" 00040 00041 typedef struct _SCANTOASCII { 00042 USHORT ScanCode; 00043 UCHAR Normal; 00044 UCHAR Shift; 00045 } SCANTOASCII, *PSCANTOASCII; 00046 00047 SCANTOASCII ScanToAscii[] = { 00048 {0x1e, 'a', 'A' }, 00049 {0x30, 'b', 'B' }, 00050 {0x2e, 'c', 'C' }, 00051 {0x20, 'd', 'D' }, 00052 {0x12, 'e', 'E' }, 00053 {0x21, 'f', 'F' }, 00054 {0x22, 'g', 'G' }, 00055 {0x23, 'h', 'H' }, 00056 {0x17, 'i', 'I' }, 00057 {0x24, 'j', 'J' }, 00058 {0x25, 'k', 'K' }, 00059 {0x26, 'l', 'L' }, 00060 {0x32, 'm', 'M' }, 00061 {0x31, 'n', 'N' }, 00062 {0x18, 'o', 'O' }, 00063 {0x19, 'p', 'P' }, 00064 {0x10, 'q', 'Q' }, 00065 {0x13, 'r', 'R' }, 00066 {0x1f, 's', 'S' }, 00067 {0x14, 't', 'T' }, 00068 {0x16, 'u', 'U' }, 00069 {0x2f, 'v', 'V' }, 00070 {0x11, 'w', 'W' }, 00071 {0x2d, 'x', 'X' }, 00072 {0x15, 'y', 'Y' }, 00073 {0x2c, 'z', 'Z' }, 00074 00075 {0x02, '1', '!' }, 00076 {0x03, '2', '@' }, 00077 {0x04, '3', '#' }, 00078 {0x05, '4', '$' }, 00079 {0x06, '5', '%' }, 00080 {0x07, '6', '^' }, 00081 {0x08, '7', '&' }, 00082 {0x09, '8', '*' }, 00083 {0x0a, '9', '(' }, 00084 {0x0b, '0', ')' }, 00085 00086 {0x29, '\'', '~' }, 00087 {0x0c, '-', '_' }, 00088 {0x0d, '=', '+' }, 00089 {0x1a, '[', '{' }, 00090 {0x1b, ']', '}' }, 00091 {0x2b, '\\', '|' }, 00092 {0x27, ';', ':' }, 00093 {0x28, '\'', '"' }, 00094 {0x33, ',', '<' }, 00095 {0x34, '.', '>' }, 00096 {0x35, '/', '?' }, 00097 00098 {0x4a, '-', '-' }, 00099 {0x4e, '+', '+' }, 00100 {0x37, '*', '*' }, 00101 00102 {0x39, ' ', ' ' }, 00103 00104 {0x1c, '\r', '\r'}, 00105 {0x0e, 0x08, 0x08}, /* backspace */ 00106 00107 {0, 0, 0} 00108 }; 00109 00110 00111 static void IntUpdateControlKeyState(LPDWORD State, PKEYBOARD_INPUT_DATA InputData) 00112 { 00113 DWORD Value = 0; 00114 00115 if(InputData->Flags & KEY_E1) /* Only the pause key has E1 */ 00116 return; 00117 00118 if(!(InputData->Flags & KEY_E0)){ 00119 switch(InputData->MakeCode){ 00120 case 0x2a: 00121 case 0x36: 00122 Value = SHIFT_PRESSED; 00123 break; 00124 case 0x1d: 00125 Value = LEFT_CTRL_PRESSED; 00126 break; 00127 case 0x38: 00128 Value = LEFT_ALT_PRESSED; 00129 break; 00130 case 0x45: 00131 Value = NUMLOCK_ON; 00132 if (!(InputData->Flags & KEY_BREAK)) 00133 *State ^= Value; 00134 return; 00135 default: 00136 return; 00137 } 00138 } else { 00139 switch(InputData->MakeCode){ 00140 case 0x1d: 00141 Value = RIGHT_CTRL_PRESSED; 00142 break; 00143 case 0x38: 00144 Value = RIGHT_ALT_PRESSED; 00145 break; 00146 default: 00147 return; 00148 } 00149 } 00150 00151 if(InputData->Flags & KEY_BREAK) 00152 *State &= ~Value; 00153 else 00154 *State |= Value; 00155 } 00156 00157 static UCHAR IntAsciiFromInput(PKEYBOARD_INPUT_DATA InputData, DWORD KeyState) 00158 { 00159 UINT Counter = 0; 00160 00161 while(ScanToAscii[Counter].ScanCode != 0){ 00162 if(ScanToAscii[Counter].ScanCode == InputData->MakeCode){ 00163 if(KeyState & SHIFT_PRESSED) 00164 return ScanToAscii[Counter].Shift; 00165 return ScanToAscii[Counter].Normal; 00166 } 00167 Counter++; 00168 } 00169 return 0; 00170 } 00171 00172 /* 00173 * Only the bKeyDown and AsciiChar members are used in the zenwinx library. 00174 */ 00175 void IntTranslateKey(PKEYBOARD_INPUT_DATA InputData, KBD_RECORD *kbd_rec) 00176 { 00177 static DWORD dwControlKeyState; 00178 00179 kbd_rec->wVirtualScanCode = InputData->MakeCode; 00180 kbd_rec->bKeyDown = (InputData->Flags & KEY_BREAK) ? FALSE : TRUE; 00181 00182 IntUpdateControlKeyState(&dwControlKeyState, InputData); 00183 kbd_rec->dwControlKeyState = dwControlKeyState; 00184 00185 if(InputData->Flags & KEY_E0) 00186 kbd_rec->dwControlKeyState |= ENHANCED_KEY; 00187 00188 kbd_rec->AsciiChar = IntAsciiFromInput(InputData,kbd_rec->dwControlKeyState); 00189 } 00190