Use SendNotifyMessage() for WM_SYNCPAINT.
[wine.git] / windows / keyboard.c
blobbcee740f6070404c1660e7bcbd49ec6a00fa1c17
1 /*
2 * KEYBOARD driver
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
12 #include <stdlib.h>
13 #include <string.h>
14 #include <ctype.h>
16 #include "windef.h"
17 #include "wingdi.h"
18 #include "winuser.h"
19 #include "wine/keyboard16.h"
20 #include "win.h"
21 #include "heap.h"
22 #include "keyboard.h"
23 #include "user.h"
24 #include "message.h"
25 #include "callback.h"
26 #include "builtin16.h"
27 #include "debugtools.h"
28 #include "winerror.h"
30 DEFAULT_DEBUG_CHANNEL(keyboard);
31 DECLARE_DEBUG_CHANNEL(event);
33 /**********************************************************************/
35 static LPKEYBD_EVENT_PROC DefKeybEventProc = NULL;
36 LPBYTE pKeyStateTable = NULL;
38 /***********************************************************************
39 * KEYBOARD_Inquire (KEYBOARD.1)
41 WORD WINAPI KEYBOARD_Inquire(LPKBINFO kbInfo)
43 kbInfo->Begin_First_Range = 0;
44 kbInfo->End_First_Range = 0;
45 kbInfo->Begin_Second_Range = 0;
46 kbInfo->End_Second_Range = 0;
47 kbInfo->StateSize = 16;
49 return sizeof(KBINFO);
52 /***********************************************************************
53 * KEYBOARD_Enable (KEYBOARD.2)
55 VOID WINAPI KEYBOARD_Enable( LPKEYBD_EVENT_PROC lpKeybEventProc,
56 LPBYTE lpKeyState )
58 static BOOL initDone = FALSE;
60 THUNK_Free( (FARPROC)DefKeybEventProc );
62 DefKeybEventProc = lpKeybEventProc;
63 pKeyStateTable = lpKeyState;
65 /* all states to false */
66 memset( lpKeyState, 0, 256 );
68 if (!initDone) USER_Driver.pInitKeyboard();
69 initDone = TRUE;
72 /**********************************************************************/
74 static VOID WINAPI KEYBOARD_CallKeybdEventProc( FARPROC16 proc,
75 BYTE bVk, BYTE bScan,
76 DWORD dwFlags, DWORD dwExtraInfo )
78 CONTEXT86 context;
80 memset( &context, 0, sizeof(context) );
81 context.SegCs = SELECTOROF( proc );
82 context.Eip = OFFSETOF( proc );
83 context.Eax = bVk | ((dwFlags & KEYEVENTF_KEYUP)? 0x8000 : 0);
84 context.Ebx = bScan | ((dwFlags & KEYEVENTF_EXTENDEDKEY) ? 0x100 : 0);
85 context.Esi = LOWORD( dwExtraInfo );
86 context.Edi = HIWORD( dwExtraInfo );
88 wine_call_to_16_regs_short( &context, 0 );
91 /**********************************************************************/
93 VOID WINAPI WIN16_KEYBOARD_Enable( FARPROC16 proc, LPBYTE lpKeyState )
95 LPKEYBD_EVENT_PROC thunk =
96 (LPKEYBD_EVENT_PROC)THUNK_Alloc( proc, (RELAY)KEYBOARD_CallKeybdEventProc );
98 KEYBOARD_Enable( thunk, lpKeyState );
101 /***********************************************************************
102 * KEYBOARD_Disable (KEYBOARD.3)
104 VOID WINAPI KEYBOARD_Disable(VOID)
106 THUNK_Free( (FARPROC)DefKeybEventProc );
108 DefKeybEventProc = NULL;
109 pKeyStateTable = NULL;
112 /***********************************************************************
113 * KEYBOARD_SendEvent
115 void KEYBOARD_SendEvent( BYTE bVk, BYTE bScan, DWORD dwFlags,
116 DWORD posX, DWORD posY, DWORD time )
118 WINE_KEYBDEVENT wke;
119 int iWndsLocks;
121 if ( !DefKeybEventProc ) return;
123 TRACE_(event)("(%d,%d,%04lX)\n", bVk, bScan, dwFlags );
125 wke.magic = WINE_KEYBDEVENT_MAGIC;
126 wke.posX = posX;
127 wke.posY = posY;
128 wke.time = time;
130 /* To avoid deadlocks, we have to suspend all locks on windows structures
131 before the program control is passed to the keyboard driver */
132 iWndsLocks = WIN_SuspendWndsLock();
133 DefKeybEventProc( bVk, bScan, dwFlags, (DWORD)&wke );
134 WIN_RestoreWndsLock(iWndsLocks);
137 /**********************************************************************
138 * SetSpeed16 (KEYBOARD.7)
140 WORD WINAPI SetSpeed16(WORD unused)
142 FIXME("(%04x): stub\n", unused);
143 return 0xffff;
146 /**********************************************************************
147 * ScreenSwitchEnable (KEYBOARD.100)
149 VOID WINAPI ScreenSwitchEnable16(WORD unused)
151 FIXME("(%04x): stub\n", unused);
154 /**********************************************************************
155 * OemKeyScan (KEYBOARD.128)(USER32.401)
157 DWORD WINAPI OemKeyScan(WORD wOemChar)
159 TRACE("*OemKeyScan (%d)\n", wOemChar);
161 return wOemChar;
164 /**********************************************************************
165 * VkKeyScan [KEYBOARD.129]
167 * VkKeyScan translates an ANSI character to a virtual-key and shift code
168 * for the current keyboard.
169 * high-order byte yields :
170 * 0 Unshifted
171 * 1 Shift
172 * 2 Ctrl
173 * 3-5 Shift-key combinations that are not used for characters
174 * 6 Ctrl-Alt
175 * 7 Ctrl-Alt-Shift
176 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
177 * FIXME : works ok except for dead chars :
178 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
179 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
182 WORD WINAPI VkKeyScan16(CHAR cChar)
184 return USER_Driver.pVkKeyScan(cChar);
187 /******************************************************************************
188 * GetKeyboardType16 (KEYBOARD.130)
190 INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag)
192 TRACE("(%d)\n", nTypeFlag);
193 switch(nTypeFlag)
195 case 0: /* Keyboard type */
196 return 4; /* AT-101 */
197 break;
198 case 1: /* Keyboard Subtype */
199 return 0; /* There are no defined subtypes */
200 break;
201 case 2: /* Number of F-keys */
202 return 12; /* We're doing an 101 for now, so return 12 F-keys */
203 break;
204 default:
205 WARN("Unknown type\n");
206 return 0; /* The book says 0 here, so 0 */
210 /******************************************************************************
211 * MapVirtualKey16 (KEYBOARD.131)
213 * MapVirtualKey translates keycodes from one format to another
215 UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
217 return USER_Driver.pMapVirtualKey(wCode,wMapType);
220 /****************************************************************************
221 * GetKBCodePage16 (KEYBOARD.132)
223 INT16 WINAPI GetKBCodePage16(void)
225 TRACE("(void)\n");
226 return 850;
229 /****************************************************************************
230 * GetKeyNameText16 (KEYBOARD.133)
232 INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
234 return USER_Driver.pGetKeyNameText(lParam, lpBuffer, nSize);
237 /****************************************************************************
238 * ToAscii (KEYBOARD.4)
240 * The ToAscii function translates the specified virtual-key code and keyboard
241 * state to the corresponding Windows character or characters.
243 * If the specified key is a dead key, the return value is negative. Otherwise,
244 * it is one of the following values:
245 * Value Meaning
246 * 0 The specified virtual key has no translation for the current state of the keyboard.
247 * 1 One Windows character was copied to the buffer.
248 * 2 Two characters were copied to the buffer. This usually happens when a
249 * dead-key character (accent or diacritic) stored in the keyboard layout cannot
250 * be composed with the specified virtual key to form a single character.
252 * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
255 INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState,
256 LPVOID lpChar, UINT16 flags)
258 return ToAscii( virtKey, scanCode, lpKeyState, lpChar, flags );
261 /***********************************************************************
262 * KEYBOARD_GetBeepActive
264 BOOL KEYBOARD_GetBeepActive()
266 return USER_Driver.pGetBeepActive();
269 /***********************************************************************
270 * KEYBOARD_SetBeepActive
272 void KEYBOARD_SetBeepActive(BOOL bActivate)
274 USER_Driver.pSetBeepActive(bActivate);
277 /***********************************************************************
278 * MessageBeep16 (USER.104)
280 void WINAPI MessageBeep16( UINT16 i )
282 MessageBeep( i );
285 /***********************************************************************
286 * MessageBeep (USER32.390)
288 BOOL WINAPI MessageBeep( UINT i )
290 USER_Driver.pBeep();
291 return TRUE;