4 * Copyright 1993 Bob Amstadt
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1997 David Faure
7 * Copyright 1998 Morten Welinder
8 * Copyright 1998 Ulrich Weigand
17 #include "wine/keyboard16.h"
23 #include "debugtools.h"
27 /**********************************************************************/
29 KEYBOARD_DRIVER *KEYBOARD_Driver = NULL;
31 static LPKEYBD_EVENT_PROC DefKeybEventProc = NULL;
32 LPBYTE pKeyStateTable = NULL;
34 /***********************************************************************
35 * KEYBOARD_Inquire (KEYBOARD.1)
37 WORD WINAPI KEYBOARD_Inquire(LPKBINFO kbInfo)
39 kbInfo->Begin_First_Range = 0;
40 kbInfo->End_First_Range = 0;
41 kbInfo->Begin_Second_Range = 0;
42 kbInfo->End_Second_Range = 0;
43 kbInfo->StateSize = 16;
45 return sizeof(KBINFO);
48 /***********************************************************************
49 * KEYBOARD_Enable (KEYBOARD.2)
51 VOID WINAPI KEYBOARD_Enable( LPKEYBD_EVENT_PROC lpKeybEventProc,
54 static BOOL initDone = FALSE;
56 DefKeybEventProc = lpKeybEventProc;
57 pKeyStateTable = lpKeyState;
59 /* all states to false */
60 memset( lpKeyState, 0, sizeof(lpKeyState) );
62 if (!initDone) KEYBOARD_Driver->pInit();
66 /***********************************************************************
67 * KEYBOARD_Disable (KEYBOARD.3)
69 VOID WINAPI KEYBOARD_Disable(VOID)
71 DefKeybEventProc = NULL;
72 pKeyStateTable = NULL;
75 /***********************************************************************
78 void KEYBOARD_SendEvent( BYTE bVk, BYTE bScan, DWORD dwFlags,
79 DWORD posX, DWORD posY, DWORD time )
83 if ( !DefKeybEventProc ) return;
85 TRACE( event, "(%d,%d,%04lX)\n", bVk, bScan, dwFlags );
87 wke.magic = WINE_KEYBDEVENT_MAGIC;
92 DefKeybEventProc( bVk, bScan, dwFlags, (DWORD)&wke );
95 /**********************************************************************
96 * ScreenSwitchEnable (KEYBOARD.100)
98 VOID WINAPI ScreenSwitchEnable16(WORD unused)
100 FIXME(keyboard,"(%04x): stub\n",unused);
103 /**********************************************************************
104 * OemKeyScan (KEYBOARD.128)(USER32.401)
106 DWORD WINAPI OemKeyScan(WORD wOemChar)
108 TRACE(keyboard,"*OemKeyScan (%d)\n",wOemChar);
113 /**********************************************************************
114 * VkKeyScan [KEYBOARD.129]
116 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
117 * for the current keyboard.
118 * high-order byte yields :
122 * 3-5 Shift-key combinations that are not used for characters
125 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
126 * FIXME : works ok except for dead chars :
127 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
128 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
131 WORD WINAPI VkKeyScan16(CHAR cChar)
133 return KEYBOARD_Driver->pVkKeyScan(cChar);
136 /******************************************************************************
137 * GetKeyboardType16 (KEYBOARD.130)
139 INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag)
141 TRACE(keyboard,"(%d)\n",nTypeFlag);
144 case 0: /* Keyboard type */
145 return 4; /* AT-101 */
147 case 1: /* Keyboard Subtype */
148 return 0; /* There are no defined subtypes */
150 case 2: /* Number of F-keys */
151 return 12; /* We're doing an 101 for now, so return 12 F-keys */
154 WARN(keyboard, "Unknown type\n");
155 return 0; /* The book says 0 here, so 0 */
159 /******************************************************************************
160 * MapVirtualKey16 (KEYBOARD.131)
162 * MapVirtualKey translates keycodes from one format to another
164 UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
166 return KEYBOARD_Driver->pMapVirtualKey(wCode,wMapType);
169 /****************************************************************************
170 * GetKBCodePage16 (KEYBOARD.132)
172 INT16 WINAPI GetKBCodePage16(void)
174 TRACE(keyboard,"(void)\n");
178 /****************************************************************************
179 * GetKeyNameText16 (KEYBOARD.133)
181 INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
183 return KEYBOARD_Driver->pGetKeyNameText(lParam, lpBuffer, nSize);
186 /****************************************************************************
187 * ToAscii (KEYBOARD.4)
189 * The ToAscii function translates the specified virtual-key code and keyboard
190 * state to the corresponding Windows character or characters.
192 * If the specified key is a dead key, the return value is negative. Otherwise,
193 * it is one of the following values:
195 * 0 The specified virtual key has no translation for the current state of the keyboard.
196 * 1 One Windows character was copied to the buffer.
197 * 2 Two characters were copied to the buffer. This usually happens when a
198 * dead-key character (accent or diacritic) stored in the keyboard layout cannot
199 * be composed with the specified virtual key to form a single character.
201 * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
204 INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState,
205 LPVOID lpChar, UINT16 flags)
207 return KEYBOARD_Driver->pToAscii(
208 virtKey, scanCode, lpKeyState, lpChar, flags
212 /***********************************************************************
213 * KEYBOARD_GetBeepActive
215 BOOL KEYBOARD_GetBeepActive()
217 return KEYBOARD_Driver->pGetBeepActive();
220 /***********************************************************************
221 * KEYBOARD_SetBeepActive
223 void KEYBOARD_SetBeepActive(BOOL bActivate)
225 KEYBOARD_Driver->pSetBeepActive(bActivate);
228 /***********************************************************************
231 void KEYBOARD_Beep(void)
233 KEYBOARD_Driver->pBeep();