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";
9 #include "prototypes.h"
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: 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
;
36 DWORD
OemKeyScan(WORD wOemChar
)
38 dprintf_keyboard(stddeb
,"*OemKeyScan (%d)\n",wOemChar
);
43 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
44 * for the current keyboard. */
46 WORD
VkKeyScan(WORD cChar
)
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
;
59 int GetKeyboardType(int nTypeFlag
)
61 dprintf_keyboard(stddeb
,"GetKeyboardType(%d)\n",nTypeFlag
);
64 case 0: /* Keyboard type */
65 return 4; /* AT-101 */
67 case 1: /* Keyboard Subtype */
68 return 0; /* There are no defined subtypes */
70 case 2: /* Number of F-keys */
71 return 12; /* We're doing an 101 for now, so return 12 F-keys */
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
)
87 for (i
= 0 ; i
!= KeyTableSize
; i
++)
88 if (KeyTable
[i
].virtualkey
== wCode
)
89 return KeyTable
[i
].scancode
;
93 for (i
= 0 ; i
!= KeyTableSize
; i
++)
94 if (KeyTable
[i
].scancode
== wCode
)
95 return KeyTable
[i
].virtualkey
;
99 for (i
= 0 ; i
!= KeyTableSize
; i
++)
100 if (KeyTable
[i
].virtualkey
== wCode
)
101 return KeyTable
[i
].ASCII
;
105 fprintf(stderr
, "MapVirtualKey: unknown wMapType!\n");
111 int GetKbCodePage(void)
113 dprintf_keyboard(stddeb
,"GetKbCodePage()\n");
117 int GetKeyNameText(LONG lParam
, LPSTR lpBuffer
, int nSize
)
121 dprintf_keyboard(stddeb
,"GetKeyNameText(%ld,<ptr>,%d)\n",lParam
,nSize
);
126 for (i
= 0 ; i
!= KeyTableSize
; i
++)
127 if (KeyTable
[i
].scancode
== lParam
) {
128 strncpy(lpBuffer
, KeyTable
[i
].name
, nSize
);
129 return strlen(lpBuffer
);