Release 940815
[wine/gsoc-2012-control.git] / misc / keyboard.c
blobd7c9ce274ad46a08ac0d75ec2bbe0bff272079ac
1 static char RCSId[] = "$Id: keyboard.c,v 1.2 1993/09/13 18:52:02 scott Exp $";
2 static char Copyright[] = "Copyright Scott A. Laird, Erik Bos 1993, 1994";
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include "prototypes.h"
7 #include "windows.h"
8 #include "keyboard.h"
10 int ToAscii(WORD wVirtKey, WORD wScanCode, LPSTR lpKeyState,
11 LPVOID lpChar, WORD wFlags)
13 int i;
15 printf("ToAscii (%d,%d)\n",wVirtKey, wScanCode);
17 /* FIXME: this is not sufficient but better than returing -1 */
19 for (i = 0 ; i != KeyTableSize ; i++)
20 if (KeyTable[i].virtualkey == wVirtKey) {
21 *(BYTE*)lpChar++ = *KeyTable[i].name;
22 *(BYTE*)lpChar = 0;
23 return 1;
26 *(BYTE*)lpChar = 0;
27 return 0;
30 DWORD OemKeyScan(WORD wOemChar)
32 printf("*OemKeyScan (%d)\n",wOemChar);
34 return wOemChar;
37 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
38 * for the current keyboard. */
40 WORD VkKeyScan(WORD cChar)
42 int i;
44 printf("VkKeyScan (%d)\n",cChar);
46 for (i = 0 ; i != KeyTableSize ; i++)
47 if (KeyTable[i].ASCII == cChar)
48 return KeyTable[i].virtualkey;
50 return -1;
53 int GetKeyboardType(int nTypeFlag)
55 printf("GetKeyboardType(%d)\n",nTypeFlag);
56 switch(nTypeFlag)
58 case 0: /* Keyboard type */
59 return 4; /* AT-101 */
60 break;
61 case 1: /* Keyboard Subtype */
62 return 0; /* There are no defined subtypes */
63 break;
64 case 2: /* Number of F-keys */
65 return 12; /* We're doing an 101 for now, so return 12 F-keys */
66 break;
67 default:
68 fprintf(stderr, "Unknown type on GetKeyboardType\n");
69 return 0; /* The book says 0 here, so 0 */
73 /* MapVirtualKey translates keycodes from one format to another. */
75 WORD MapVirtualKey(WORD wCode, WORD wMapType)
77 int i;
79 switch(wMapType) {
80 case 0:
81 for (i = 0 ; i != KeyTableSize ; i++)
82 if (KeyTable[i].virtualkey == wCode)
83 return KeyTable[i].scancode;
84 return 0;
86 case 1:
87 for (i = 0 ; i != KeyTableSize ; i++)
88 if (KeyTable[i].scancode == wCode)
89 return KeyTable[i].virtualkey;
90 return 0;
92 case 2:
93 for (i = 0 ; i != KeyTableSize ; i++)
94 if (KeyTable[i].virtualkey == wCode)
95 return KeyTable[i].ASCII;
96 return 0;
98 default:
99 fprintf(stderr, "MapVirtualKey: unknown wMapType!\n");
100 return 0;
102 return 0;
105 int GetKbCodePage(void)
107 printf("GetKbCodePage()\n");
108 return 850;
111 int GetKeyNameText(LONG lParam, LPSTR lpBuffer, int nSize)
113 int i;
115 printf("GetKeyNameText(%d,<ptr>, %d)\n",lParam,nSize);
117 lParam >>= 16;
118 lParam &= 0xff;
120 for (i = 0 ; i != KeyTableSize ; i++)
121 if (KeyTable[i].scancode == lParam) {
122 strncpy(lpBuffer, KeyTable[i].name, nSize);
123 return strlen(lpBuffer);
126 *lpBuffer = 0;
127 return 0;