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
19 #include "wine/keyboard16.h"
26 #include "builtin16.h"
27 #include "debugtools.h"
31 DEFAULT_DEBUG_CHANNEL(keyboard)
32 DECLARE_DEBUG_CHANNEL(event)
34 /**********************************************************************/
36 static LPKEYBD_EVENT_PROC DefKeybEventProc = NULL;
37 LPBYTE pKeyStateTable = NULL;
39 /***********************************************************************
40 * KEYBOARD_Inquire (KEYBOARD.1)
42 WORD WINAPI KEYBOARD_Inquire(LPKBINFO kbInfo)
44 kbInfo->Begin_First_Range = 0;
45 kbInfo->End_First_Range = 0;
46 kbInfo->Begin_Second_Range = 0;
47 kbInfo->End_Second_Range = 0;
48 kbInfo->StateSize = 16;
50 return sizeof(KBINFO);
53 /***********************************************************************
54 * KEYBOARD_Enable (KEYBOARD.2)
56 VOID WINAPI KEYBOARD_Enable( LPKEYBD_EVENT_PROC lpKeybEventProc,
59 static BOOL initDone = FALSE;
61 THUNK_Free( (FARPROC)DefKeybEventProc );
63 DefKeybEventProc = lpKeybEventProc;
64 pKeyStateTable = lpKeyState;
66 /* all states to false */
67 memset( lpKeyState, 0, 256 );
69 if (!initDone) USER_Driver.pInitKeyboard();
73 static VOID WINAPI KEYBOARD_CallKeybdEventProc( FARPROC16 proc,
75 DWORD dwFlags, DWORD dwExtraInfo )
79 memset( &context, 0, sizeof(context) );
80 CS_reg(&context) = SELECTOROF( proc );
81 EIP_reg(&context) = OFFSETOF( proc );
82 AH_reg(&context) = (dwFlags & KEYEVENTF_KEYUP)? 0x80 : 0;
83 AL_reg(&context) = bVk;
84 BH_reg(&context) = (dwFlags & KEYEVENTF_EXTENDEDKEY)? 1 : 0;
85 BL_reg(&context) = bScan;
86 SI_reg(&context) = LOWORD( dwExtraInfo );
87 DI_reg(&context) = HIWORD( dwExtraInfo );
89 CallTo16RegisterShort( &context, 0 );
92 VOID WINAPI WIN16_KEYBOARD_Enable( FARPROC16 proc, LPBYTE lpKeyState )
94 LPKEYBD_EVENT_PROC thunk =
95 (LPKEYBD_EVENT_PROC)THUNK_Alloc( proc, (RELAY)KEYBOARD_CallKeybdEventProc );
97 KEYBOARD_Enable( thunk, lpKeyState );
100 /***********************************************************************
101 * KEYBOARD_Disable (KEYBOARD.3)
103 VOID WINAPI KEYBOARD_Disable(VOID)
105 THUNK_Free( (FARPROC)DefKeybEventProc );
107 DefKeybEventProc = NULL;
108 pKeyStateTable = NULL;
111 /***********************************************************************
114 void KEYBOARD_SendEvent( BYTE bVk, BYTE bScan, DWORD dwFlags,
115 DWORD posX, DWORD posY, DWORD time )
120 if ( !DefKeybEventProc ) return;
122 TRACE_(event)("(%d,%d,%04lX)\n", bVk, bScan, dwFlags );
124 wke.magic = WINE_KEYBDEVENT_MAGIC;
129 /* To avoid deadlocks, we have to suspend all locks on windows structures
130 before the program control is passed to the keyboard driver */
131 iWndsLocks = WIN_SuspendWndsLock();
132 DefKeybEventProc( bVk, bScan, dwFlags, (DWORD)&wke );
133 WIN_RestoreWndsLock(iWndsLocks);
136 /**********************************************************************
137 * SetSpeed16 (KEYBOARD.7)
139 WORD WINAPI SetSpeed16(WORD unused)
141 FIXME("(%04x): stub\n", unused);
145 /**********************************************************************
146 * ScreenSwitchEnable (KEYBOARD.100)
148 VOID WINAPI ScreenSwitchEnable16(WORD unused)
150 FIXME("(%04x): stub\n", unused);
153 /**********************************************************************
154 * OemKeyScan (KEYBOARD.128)(USER32.401)
156 DWORD WINAPI OemKeyScan(WORD wOemChar)
158 TRACE("*OemKeyScan (%d)\n", wOemChar);
163 /**********************************************************************
164 * VkKeyScan [KEYBOARD.129]
166 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
167 * for the current keyboard.
168 * high-order byte yields :
172 * 3-5 Shift-key combinations that are not used for characters
175 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
176 * FIXME : works ok except for dead chars :
177 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
178 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
181 WORD WINAPI VkKeyScan16(CHAR cChar)
183 return USER_Driver.pVkKeyScan(cChar);
186 /******************************************************************************
187 * GetKeyboardType16 (KEYBOARD.130)
189 INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag)
191 TRACE("(%d)\n", nTypeFlag);
194 case 0: /* Keyboard type */
195 return 4; /* AT-101 */
197 case 1: /* Keyboard Subtype */
198 return 0; /* There are no defined subtypes */
200 case 2: /* Number of F-keys */
201 return 12; /* We're doing an 101 for now, so return 12 F-keys */
204 WARN("Unknown type\n");
205 return 0; /* The book says 0 here, so 0 */
209 /******************************************************************************
210 * MapVirtualKey16 (KEYBOARD.131)
212 * MapVirtualKey translates keycodes from one format to another
214 UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
216 return USER_Driver.pMapVirtualKey(wCode,wMapType);
219 /****************************************************************************
220 * GetKBCodePage16 (KEYBOARD.132)
222 INT16 WINAPI GetKBCodePage16(void)
228 /****************************************************************************
229 * GetKeyNameText16 (KEYBOARD.133)
231 INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
233 return USER_Driver.pGetKeyNameText(lParam, lpBuffer, nSize);
236 /****************************************************************************
237 * ToAscii (KEYBOARD.4)
239 * The ToAscii function translates the specified virtual-key code and keyboard
240 * state to the corresponding Windows character or characters.
242 * If the specified key is a dead key, the return value is negative. Otherwise,
243 * it is one of the following values:
245 * 0 The specified virtual key has no translation for the current state of the keyboard.
246 * 1 One Windows character was copied to the buffer.
247 * 2 Two characters were copied to the buffer. This usually happens when a
248 * dead-key character (accent or diacritic) stored in the keyboard layout cannot
249 * be composed with the specified virtual key to form a single character.
251 * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
254 INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState,
255 LPVOID lpChar, UINT16 flags)
257 return USER_Driver.pToAscii( virtKey, scanCode, lpKeyState, lpChar, flags );
260 /***********************************************************************
261 * KEYBOARD_GetBeepActive
263 BOOL KEYBOARD_GetBeepActive()
265 return USER_Driver.pGetBeepActive();
268 /***********************************************************************
269 * KEYBOARD_SetBeepActive
271 void KEYBOARD_SetBeepActive(BOOL bActivate)
273 USER_Driver.pSetBeepActive(bActivate);
276 /***********************************************************************
277 * MessageBeep16 (USER.104)
279 void WINAPI MessageBeep16( UINT16 i )
284 /***********************************************************************
285 * MessageBeep (USER32.390)
287 BOOL WINAPI MessageBeep( UINT i )