2 static char RCSId[] = "$Id: keyboard.c,v 1.2 1993/09/13 18:52:02 scott Exp $";
3 static char Copyright[] = "Copyright Scott A. Laird, Erik Bos 1993, 1994";
13 /* #define DEBUG_KEYBOARD */
16 int ToAscii(WORD wVirtKey, WORD wScanCode, LPSTR lpKeyState,
17 LPVOID lpChar, WORD wFlags)
21 dprintf_keyboard(stddeb,"ToAscii (%d,%d)\n",wVirtKey, wScanCode);
23 /* FIXME: codepage is broken */
25 for (i = 0 ; i != KeyTableSize ; i++)
26 if (KeyTable[i].virtualkey == wVirtKey)
28 dprintf_keyboard(stddeb,"\t\tchar = %s\n", KeyTable[i].name);
29 if( isprint(KeyTable[i].ASCII) || isspace(KeyTable[i].ASCII) )
31 *(BYTE*)lpChar = KeyTable[i].ASCII;
32 *(((BYTE*)lpChar) + 1) = 0;
34 if( isalpha( *(BYTE*)lpChar ) )
35 if( (lpKeyState[VK_CAPITAL]<0 && !lpKeyState[VK_SHIFT]) ||
36 (!lpKeyState[VK_CAPITAL] && lpKeyState[VK_SHIFT]<0) )
37 *(BYTE*)lpChar = toupper( *(BYTE*)lpChar );
39 *(BYTE*)lpChar = tolower( *(BYTE*)lpChar );
49 DWORD OemKeyScan(WORD wOemChar)
51 dprintf_keyboard(stddeb,"*OemKeyScan (%d)\n",wOemChar);
56 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
57 * for the current keyboard. */
59 WORD VkKeyScan(WORD cChar)
63 dprintf_keyboard(stddeb,"VkKeyScan (%d)\n",cChar);
65 for (i = 0 ; i != KeyTableSize ; i++)
66 if (KeyTable[i].ASCII == cChar)
67 return KeyTable[i].virtualkey;
72 int GetKeyboardType(int nTypeFlag)
74 dprintf_keyboard(stddeb,"GetKeyboardType(%d)\n",nTypeFlag);
77 case 0: /* Keyboard type */
78 return 4; /* AT-101 */
80 case 1: /* Keyboard Subtype */
81 return 0; /* There are no defined subtypes */
83 case 2: /* Number of F-keys */
84 return 12; /* We're doing an 101 for now, so return 12 F-keys */
87 fprintf(stderr, "Unknown type on GetKeyboardType\n");
88 return 0; /* The book says 0 here, so 0 */
92 /* MapVirtualKey translates keycodes from one format to another. */
94 WORD MapVirtualKey(WORD wCode, WORD wMapType)
100 for (i = 0 ; i != KeyTableSize ; i++)
101 if (KeyTable[i].virtualkey == wCode)
102 return KeyTable[i].scancode;
106 for (i = 0 ; i != KeyTableSize ; i++)
107 if (KeyTable[i].scancode == wCode)
108 return KeyTable[i].virtualkey;
112 for (i = 0 ; i != KeyTableSize ; i++)
113 if (KeyTable[i].virtualkey == wCode)
114 return KeyTable[i].ASCII;
118 fprintf(stderr, "MapVirtualKey: unknown wMapType!\n");
124 int GetKbCodePage(void)
126 dprintf_keyboard(stddeb,"GetKbCodePage()\n");
130 int GetKeyNameText(LONG lParam, LPSTR lpBuffer, int nSize)
134 dprintf_keyboard(stddeb,"GetKeyNameText(%ld,<ptr>,%d)\n",lParam,nSize);
139 for (i = 0 ; i != KeyTableSize ; i++)
140 if (KeyTable[i].scancode == lParam) {
141 lstrcpyn(lpBuffer, KeyTable[i].name, nSize);
142 return strlen(lpBuffer);