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
20 #include "wine/keyboard16.h"
27 #include "builtin16.h"
28 #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 * 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 /***********************************************************************
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 /**********************************************************************/
75 static VOID WINAPI
KEYBOARD_CallKeybdEventProc( FARPROC16 proc
,
77 DWORD dwFlags
, DWORD dwExtraInfo
)
81 memset( &context
, 0, sizeof(context
) );
82 context
.SegCs
= SELECTOROF( proc
);
83 context
.Eip
= OFFSETOF( proc
);
84 context
.Eax
= bVk
| ((dwFlags
& KEYEVENTF_KEYUP
)? 0x8000 : 0);
85 context
.Ebx
= bScan
| ((dwFlags
& KEYEVENTF_EXTENDEDKEY
) ? 0x100 : 0);
86 context
.Esi
= LOWORD( dwExtraInfo
);
87 context
.Edi
= HIWORD( dwExtraInfo
);
89 wine_call_to_16_regs_short( &context
, 0 );
92 /**********************************************************************/
94 VOID WINAPI
WIN16_KEYBOARD_Enable( FARPROC16 proc
, LPBYTE lpKeyState
)
96 LPKEYBD_EVENT_PROC thunk
=
97 (LPKEYBD_EVENT_PROC
)THUNK_Alloc( proc
, (RELAY
)KEYBOARD_CallKeybdEventProc
);
99 KEYBOARD_Enable( thunk
, lpKeyState
);
102 /***********************************************************************
103 * Disable (KEYBOARD.3)
105 VOID WINAPI
KEYBOARD_Disable(VOID
)
107 THUNK_Free( (FARPROC
)DefKeybEventProc
);
109 DefKeybEventProc
= NULL
;
110 pKeyStateTable
= NULL
;
113 /***********************************************************************
116 void KEYBOARD_SendEvent( BYTE bVk
, BYTE bScan
, DWORD dwFlags
,
117 DWORD posX
, DWORD posY
, DWORD time
)
122 if ( !DefKeybEventProc
) return;
124 TRACE_(event
)("(%d,%d,%04lX)\n", bVk
, bScan
, dwFlags
);
126 wke
.magic
= WINE_KEYBDEVENT_MAGIC
;
131 /* To avoid deadlocks, we have to suspend all locks on windows structures
132 before the program control is passed to the keyboard driver */
133 iWndsLocks
= WIN_SuspendWndsLock();
134 DefKeybEventProc( bVk
, bScan
, dwFlags
, (DWORD
)&wke
);
135 WIN_RestoreWndsLock(iWndsLocks
);
138 /**********************************************************************
139 * SetSpeed (KEYBOARD.7)
141 WORD WINAPI
SetSpeed16(WORD unused
)
143 FIXME("(%04x): stub\n", unused
);
147 /**********************************************************************
148 * ScreenSwitchEnable (KEYBOARD.100)
150 VOID WINAPI
ScreenSwitchEnable16(WORD unused
)
152 FIXME("(%04x): stub\n", unused
);
155 /**********************************************************************
156 * OemKeyScan (KEYBOARD.128) (USER32.@)
158 DWORD WINAPI
OemKeyScan(WORD wOemChar
)
160 TRACE("*OemKeyScan (%d)\n", wOemChar
);
165 /**********************************************************************
166 * VkKeyScan (KEYBOARD.129)
168 * VkKeyScan translates an ANSI character to a virtual-key and shift code
169 * for the current keyboard.
170 * high-order byte yields :
174 * 3-5 Shift-key combinations that are not used for characters
177 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
178 * FIXME : works ok except for dead chars :
179 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
180 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
183 WORD WINAPI
VkKeyScan16(CHAR cChar
)
185 return USER_Driver
.pVkKeyScan(cChar
);
188 /******************************************************************************
189 * GetKeyboardType (KEYBOARD.130)
191 INT16 WINAPI
GetKeyboardType16(INT16 nTypeFlag
)
193 TRACE("(%d)\n", nTypeFlag
);
196 case 0: /* Keyboard type */
197 return 4; /* AT-101 */
199 case 1: /* Keyboard Subtype */
200 return 0; /* There are no defined subtypes */
202 case 2: /* Number of F-keys */
203 return 12; /* We're doing an 101 for now, so return 12 F-keys */
206 WARN("Unknown type\n");
207 return 0; /* The book says 0 here, so 0 */
211 /******************************************************************************
212 * MapVirtualKey (KEYBOARD.131)
214 * MapVirtualKey translates keycodes from one format to another
216 UINT16 WINAPI
MapVirtualKey16(UINT16 wCode
, UINT16 wMapType
)
218 return USER_Driver
.pMapVirtualKey(wCode
,wMapType
);
221 /****************************************************************************
222 * GetKBCodePage (KEYBOARD.132)
224 INT16 WINAPI
GetKBCodePage16(void)
226 return GetKBCodePage();
229 /****************************************************************************
230 * GetKeyNameText (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:
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 * MessageBeep (USER.104)
280 void WINAPI
MessageBeep16( UINT16 i
)
285 /***********************************************************************
286 * MessageBeep (USER32.@)
288 BOOL WINAPI
MessageBeep( UINT i
)