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"
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
,
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();
72 static VOID WINAPI
KEYBOARD_CallKeybdEventProc( FARPROC16 proc
,
74 DWORD dwFlags
, DWORD dwExtraInfo
)
78 memset( &context
, 0, sizeof(context
) );
79 context
.SegCs
= SELECTOROF( proc
);
80 context
.Eip
= OFFSETOF( proc
);
81 context
.Eax
= bVk
| ((dwFlags
& KEYEVENTF_KEYUP
)? 0x8000 : 0);
82 context
.Ebx
= bScan
| ((dwFlags
& KEYEVENTF_EXTENDEDKEY
) ? 0x100 : 0);
83 context
.Esi
= LOWORD( dwExtraInfo
);
84 context
.Edi
= HIWORD( dwExtraInfo
);
86 CallTo16RegisterShort( &context
, 0 );
89 VOID WINAPI
WIN16_KEYBOARD_Enable( FARPROC16 proc
, LPBYTE lpKeyState
)
91 LPKEYBD_EVENT_PROC thunk
=
92 (LPKEYBD_EVENT_PROC
)THUNK_Alloc( proc
, (RELAY
)KEYBOARD_CallKeybdEventProc
);
94 KEYBOARD_Enable( thunk
, lpKeyState
);
97 /***********************************************************************
98 * KEYBOARD_Disable (KEYBOARD.3)
100 VOID WINAPI
KEYBOARD_Disable(VOID
)
102 THUNK_Free( (FARPROC
)DefKeybEventProc
);
104 DefKeybEventProc
= NULL
;
105 pKeyStateTable
= NULL
;
108 /***********************************************************************
111 void KEYBOARD_SendEvent( BYTE bVk
, BYTE bScan
, DWORD dwFlags
,
112 DWORD posX
, DWORD posY
, DWORD time
)
117 if ( !DefKeybEventProc
) return;
119 TRACE_(event
)("(%d,%d,%04lX)\n", bVk
, bScan
, dwFlags
);
121 wke
.magic
= WINE_KEYBDEVENT_MAGIC
;
126 /* To avoid deadlocks, we have to suspend all locks on windows structures
127 before the program control is passed to the keyboard driver */
128 iWndsLocks
= WIN_SuspendWndsLock();
129 DefKeybEventProc( bVk
, bScan
, dwFlags
, (DWORD
)&wke
);
130 WIN_RestoreWndsLock(iWndsLocks
);
133 /**********************************************************************
134 * SetSpeed16 (KEYBOARD.7)
136 WORD WINAPI
SetSpeed16(WORD unused
)
138 FIXME("(%04x): stub\n", unused
);
142 /**********************************************************************
143 * ScreenSwitchEnable (KEYBOARD.100)
145 VOID WINAPI
ScreenSwitchEnable16(WORD unused
)
147 FIXME("(%04x): stub\n", unused
);
150 /**********************************************************************
151 * OemKeyScan (KEYBOARD.128)(USER32.401)
153 DWORD WINAPI
OemKeyScan(WORD wOemChar
)
155 TRACE("*OemKeyScan (%d)\n", wOemChar
);
160 /**********************************************************************
161 * VkKeyScan [KEYBOARD.129]
163 /* VkKeyScan translates an ANSI character to a virtual-key and shift code
164 * for the current keyboard.
165 * high-order byte yields :
169 * 3-5 Shift-key combinations that are not used for characters
172 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
173 * FIXME : works ok except for dead chars :
174 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
175 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
178 WORD WINAPI
VkKeyScan16(CHAR cChar
)
180 return USER_Driver
.pVkKeyScan(cChar
);
183 /******************************************************************************
184 * GetKeyboardType16 (KEYBOARD.130)
186 INT16 WINAPI
GetKeyboardType16(INT16 nTypeFlag
)
188 TRACE("(%d)\n", nTypeFlag
);
191 case 0: /* Keyboard type */
192 return 4; /* AT-101 */
194 case 1: /* Keyboard Subtype */
195 return 0; /* There are no defined subtypes */
197 case 2: /* Number of F-keys */
198 return 12; /* We're doing an 101 for now, so return 12 F-keys */
201 WARN("Unknown type\n");
202 return 0; /* The book says 0 here, so 0 */
206 /******************************************************************************
207 * MapVirtualKey16 (KEYBOARD.131)
209 * MapVirtualKey translates keycodes from one format to another
211 UINT16 WINAPI
MapVirtualKey16(UINT16 wCode
, UINT16 wMapType
)
213 return USER_Driver
.pMapVirtualKey(wCode
,wMapType
);
216 /****************************************************************************
217 * GetKBCodePage16 (KEYBOARD.132)
219 INT16 WINAPI
GetKBCodePage16(void)
225 /****************************************************************************
226 * GetKeyNameText16 (KEYBOARD.133)
228 INT16 WINAPI
GetKeyNameText16(LONG lParam
, LPSTR lpBuffer
, INT16 nSize
)
230 return USER_Driver
.pGetKeyNameText(lParam
, lpBuffer
, nSize
);
233 /****************************************************************************
234 * ToAscii (KEYBOARD.4)
236 * The ToAscii function translates the specified virtual-key code and keyboard
237 * state to the corresponding Windows character or characters.
239 * If the specified key is a dead key, the return value is negative. Otherwise,
240 * it is one of the following values:
242 * 0 The specified virtual key has no translation for the current state of the keyboard.
243 * 1 One Windows character was copied to the buffer.
244 * 2 Two characters were copied to the buffer. This usually happens when a
245 * dead-key character (accent or diacritic) stored in the keyboard layout cannot
246 * be composed with the specified virtual key to form a single character.
248 * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
251 INT16 WINAPI
ToAscii16(UINT16 virtKey
,UINT16 scanCode
, LPBYTE lpKeyState
,
252 LPVOID lpChar
, UINT16 flags
)
254 return ToAscii( virtKey
, scanCode
, lpKeyState
, lpChar
, flags
);
257 /***********************************************************************
258 * KEYBOARD_GetBeepActive
260 BOOL
KEYBOARD_GetBeepActive()
262 return USER_Driver
.pGetBeepActive();
265 /***********************************************************************
266 * KEYBOARD_SetBeepActive
268 void KEYBOARD_SetBeepActive(BOOL bActivate
)
270 USER_Driver
.pSetBeepActive(bActivate
);
273 /***********************************************************************
274 * MessageBeep16 (USER.104)
276 void WINAPI
MessageBeep16( UINT16 i
)
281 /***********************************************************************
282 * MessageBeep (USER32.390)
284 BOOL WINAPI
MessageBeep( UINT i
)