Release 960516
[wine.git] / misc / keyboard.c
blob8f8c31b26252c88256f73d55d2aca859a44c22a8
1 /*
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";
4 */
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include "windows.h"
11 #include "keyboard.h"
12 #include "stddebug.h"
13 /* #define DEBUG_KEYBOARD */
14 #include "debug.h"
16 int ToAscii(WORD wVirtKey, WORD wScanCode, LPSTR lpKeyState,
17 LPVOID lpChar, WORD wFlags)
19 int i;
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 );
38 else
39 *(BYTE*)lpChar = tolower( *(BYTE*)lpChar );
41 return 1;
45 *(BYTE*)lpChar = 0;
46 return 0;
49 DWORD OemKeyScan(WORD wOemChar)
51 dprintf_keyboard(stddeb,"*OemKeyScan (%d)\n",wOemChar);
53 return wOemChar;
56 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
57 * for the current keyboard. */
59 WORD VkKeyScan(WORD cChar)
61 int i;
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;
69 return -1;
72 int GetKeyboardType(int nTypeFlag)
74 dprintf_keyboard(stddeb,"GetKeyboardType(%d)\n",nTypeFlag);
75 switch(nTypeFlag)
77 case 0: /* Keyboard type */
78 return 4; /* AT-101 */
79 break;
80 case 1: /* Keyboard Subtype */
81 return 0; /* There are no defined subtypes */
82 break;
83 case 2: /* Number of F-keys */
84 return 12; /* We're doing an 101 for now, so return 12 F-keys */
85 break;
86 default:
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)
96 int i;
98 switch(wMapType) {
99 case 0:
100 for (i = 0 ; i != KeyTableSize ; i++)
101 if (KeyTable[i].virtualkey == wCode)
102 return KeyTable[i].scancode;
103 return 0;
105 case 1:
106 for (i = 0 ; i != KeyTableSize ; i++)
107 if (KeyTable[i].scancode == wCode)
108 return KeyTable[i].virtualkey;
109 return 0;
111 case 2:
112 for (i = 0 ; i != KeyTableSize ; i++)
113 if (KeyTable[i].virtualkey == wCode)
114 return KeyTable[i].ASCII;
115 return 0;
117 default:
118 fprintf(stderr, "MapVirtualKey: unknown wMapType!\n");
119 return 0;
121 return 0;
124 int GetKbCodePage(void)
126 dprintf_keyboard(stddeb,"GetKbCodePage()\n");
127 return 850;
130 int GetKeyNameText(LONG lParam, LPSTR lpBuffer, int nSize)
132 int i;
134 dprintf_keyboard(stddeb,"GetKeyNameText(%ld,<ptr>,%d)\n",lParam,nSize);
136 lParam >>= 16;
137 lParam &= 0xff;
139 for (i = 0 ; i != KeyTableSize ; i++)
140 if (KeyTable[i].scancode == lParam) {
141 lstrcpyn(lpBuffer, KeyTable[i].name, nSize);
142 return strlen(lpBuffer);
145 *lpBuffer = 0;
146 return 0;