Release 941210
[wine/multimedia.git] / misc / keyboard.c
blob9a07198f8ea9749e2f5e4572667bdab862e4ae9a
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 "prototypes.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: this is not sufficient but better than returing -1 */
25 for (i = 0 ; i != KeyTableSize ; i++)
26 if (KeyTable[i].virtualkey == wVirtKey) {
27 *(BYTE*)lpChar++ = *KeyTable[i].name;
28 *(BYTE*)lpChar = 0;
29 return 1;
32 *(BYTE*)lpChar = 0;
33 return 0;
36 DWORD OemKeyScan(WORD wOemChar)
38 dprintf_keyboard(stddeb,"*OemKeyScan (%d)\n",wOemChar);
40 return wOemChar;
43 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
44 * for the current keyboard. */
46 WORD VkKeyScan(WORD cChar)
48 int i;
50 dprintf_keyboard(stddeb,"VkKeyScan (%d)\n",cChar);
52 for (i = 0 ; i != KeyTableSize ; i++)
53 if (KeyTable[i].ASCII == cChar)
54 return KeyTable[i].virtualkey;
56 return -1;
59 int GetKeyboardType(int nTypeFlag)
61 dprintf_keyboard(stddeb,"GetKeyboardType(%d)\n",nTypeFlag);
62 switch(nTypeFlag)
64 case 0: /* Keyboard type */
65 return 4; /* AT-101 */
66 break;
67 case 1: /* Keyboard Subtype */
68 return 0; /* There are no defined subtypes */
69 break;
70 case 2: /* Number of F-keys */
71 return 12; /* We're doing an 101 for now, so return 12 F-keys */
72 break;
73 default:
74 fprintf(stderr, "Unknown type on GetKeyboardType\n");
75 return 0; /* The book says 0 here, so 0 */
79 /* MapVirtualKey translates keycodes from one format to another. */
81 WORD MapVirtualKey(WORD wCode, WORD wMapType)
83 int i;
85 switch(wMapType) {
86 case 0:
87 for (i = 0 ; i != KeyTableSize ; i++)
88 if (KeyTable[i].virtualkey == wCode)
89 return KeyTable[i].scancode;
90 return 0;
92 case 1:
93 for (i = 0 ; i != KeyTableSize ; i++)
94 if (KeyTable[i].scancode == wCode)
95 return KeyTable[i].virtualkey;
96 return 0;
98 case 2:
99 for (i = 0 ; i != KeyTableSize ; i++)
100 if (KeyTable[i].virtualkey == wCode)
101 return KeyTable[i].ASCII;
102 return 0;
104 default:
105 fprintf(stderr, "MapVirtualKey: unknown wMapType!\n");
106 return 0;
108 return 0;
111 int GetKbCodePage(void)
113 dprintf_keyboard(stddeb,"GetKbCodePage()\n");
114 return 850;
117 int GetKeyNameText(LONG lParam, LPSTR lpBuffer, int nSize)
119 int i;
121 dprintf_keyboard(stddeb,"GetKeyNameText(%ld,<ptr>,%d)\n",lParam,nSize);
123 lParam >>= 16;
124 lParam &= 0xff;
126 for (i = 0 ; i != KeyTableSize ; i++)
127 if (KeyTable[i].scancode == lParam) {
128 strncpy(lpBuffer, KeyTable[i].name, nSize);
129 return strlen(lpBuffer);
132 *lpBuffer = 0;
133 return 0;