2 * USER Input processing
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
21 #include "wine/winbase16.h"
22 #include "wine/winuser16.h"
23 #include "wine/keyboard16.h"
32 #include "debugtools.h"
37 DECLARE_DEBUG_CHANNEL(accel);
38 DECLARE_DEBUG_CHANNEL(event);
39 DECLARE_DEBUG_CHANNEL(key);
40 DECLARE_DEBUG_CHANNEL(keyboard);
41 DECLARE_DEBUG_CHANNEL(win);
43 static BOOL InputEnabled = TRUE;
44 BOOL SwappedButtons = FALSE;
46 BOOL MouseButtonsStates[3];
47 BOOL AsyncMouseButtonsStates[3];
48 BYTE InputKeyStateTable[256];
49 BYTE QueueKeyStateTable[256];
50 BYTE AsyncKeyStateTable[256];
52 /* Storage for the USER-maintained mouse positions */
59 unsigned long count : 16;
60 unsigned long code : 8;
61 unsigned long extended : 1;
62 unsigned long unused : 2;
63 unsigned long win_internal : 2;
64 unsigned long context : 1;
65 unsigned long previous : 1;
66 unsigned long transition : 1;
71 /***********************************************************************
72 * keybd_event (USER32.583)
74 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
75 DWORD dwFlags, DWORD dwExtraInfo )
82 if (!InputEnabled) return;
85 * If we are called by the Wine keyboard driver, use the additional
86 * info pointed to by the dwExtraInfo argument.
87 * Otherwise, we need to determine that info ourselves (probably
88 * less accurate, but we can't help that ...).
90 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_KEYBDEVENT) )
91 && ((WINE_KEYBDEVENT *)dwExtraInfo)->magic == WINE_KEYBDEVENT_MAGIC )
93 WINE_KEYBDEVENT *wke = (WINE_KEYBDEVENT *)dwExtraInfo;
99 time = GetTickCount();
105 keylp.lp1.code = bScan;
106 keylp.lp1.extended = (dwFlags & KEYEVENTF_EXTENDEDKEY) != 0;
107 keylp.lp1.win_internal = 0; /* this has something to do with dialogs,
108 * don't remember where I read it - AK */
109 /* it's '1' under windows, when a dialog box appears
110 * and you press one of the underlined keys - DF*/
112 if ( dwFlags & KEYEVENTF_KEYUP )
114 BOOL sysKey = (InputKeyStateTable[VK_MENU] & 0x80)
115 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
116 && !(dwFlags & KEYEVENTF_WINE_FORCEEXTENDED); /* for Alt from AltGr */
118 InputKeyStateTable[bVk] &= ~0x80;
119 keylp.lp1.previous = 1;
120 keylp.lp1.transition = 1;
121 message = sysKey ? WM_SYSKEYUP : WM_KEYUP;
125 keylp.lp1.previous = (InputKeyStateTable[bVk] & 0x80) != 0;
126 keylp.lp1.transition = 0;
128 if (!(InputKeyStateTable[bVk] & 0x80))
129 InputKeyStateTable[bVk] ^= 0x01;
130 InputKeyStateTable[bVk] |= 0x80;
132 message = (InputKeyStateTable[VK_MENU] & 0x80)
133 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
134 ? WM_SYSKEYDOWN : WM_KEYDOWN;
137 if ( message == WM_SYSKEYDOWN || message == WM_SYSKEYUP )
138 keylp.lp1.context = (InputKeyStateTable[VK_MENU] & 0x80) != 0; /* 1 if alt */
141 TRACE_(key)(" wParam=%04X, lParam=%08lX\n", bVk, keylp.lp2 );
142 TRACE_(key)(" InputKeyState=%X\n", InputKeyStateTable[bVk] );
144 hardware_event( message, bVk, keylp.lp2, PosX, PosY, time, extra );
147 /***********************************************************************
148 * WIN16_keybd_event (USER.289)
150 void WINAPI WIN16_keybd_event( CONTEXT86 *context )
154 if (AH_reg(context) & 0x80) dwFlags |= KEYEVENTF_KEYUP;
155 if (BH_reg(context) & 1 ) dwFlags |= KEYEVENTF_EXTENDEDKEY;
157 keybd_event( AL_reg(context), BL_reg(context),
158 dwFlags, MAKELONG(SI_reg(context), DI_reg(context)) );
161 /***********************************************************************
162 * mouse_event (USER32.584)
164 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
165 DWORD cButtons, DWORD dwExtraInfo )
170 if (!InputEnabled) return;
172 if ( dwFlags & MOUSEEVENTF_MOVE )
174 if ( dwFlags & MOUSEEVENTF_ABSOLUTE )
176 PosX = (dx * GetSystemMetrics(SM_CXSCREEN)) >> 16;
177 PosY = (dy * GetSystemMetrics(SM_CYSCREEN)) >> 16;
181 int width = GetSystemMetrics(SM_CXSCREEN);
182 int height = GetSystemMetrics(SM_CYSCREEN);
183 long posX = (long) PosX, posY = (long) PosY;
185 /* dx and dy can be negative numbers for relative movements */
189 /* Clip to the current screen size */
190 if (posX < 0) PosX = 0;
191 else if (posX >= width) PosX = width - 1;
194 if (posY < 0) PosY = 0;
195 else if (posY >= height) PosY = height - 1;
201 * If we are called by the Wine mouse driver, use the additional
202 * info pointed to by the dwExtraInfo argument.
203 * Otherwise, we need to determine that info ourselves (probably
204 * less accurate, but we can't help that ...).
206 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_MOUSEEVENT) )
207 && ((WINE_MOUSEEVENT *)dwExtraInfo)->magic == WINE_MOUSEEVENT_MAGIC )
209 WINE_MOUSEEVENT *wme = (WINE_MOUSEEVENT *)dwExtraInfo;
211 extra = (DWORD)wme->hWnd;
212 keyState = wme->keyState;
214 if (keyState != GET_KEYSTATE()) {
215 /* We need to update the keystate with what X provides us */
216 MouseButtonsStates[SwappedButtons ? 2 : 0] = (keyState & MK_LBUTTON ? TRUE : FALSE);
217 MouseButtonsStates[SwappedButtons ? 0 : 2] = (keyState & MK_RBUTTON ? TRUE : FALSE);
218 MouseButtonsStates[1] = (keyState & MK_MBUTTON ? TRUE : FALSE);
219 InputKeyStateTable[VK_SHIFT] = (keyState & MK_SHIFT ? 0x80 : 0);
220 InputKeyStateTable[VK_CONTROL] = (keyState & MK_CONTROL ? 0x80 : 0);
225 time = GetTickCount();
227 keyState = GET_KEYSTATE();
229 if ( dwFlags & MOUSEEVENTF_MOVE )
231 /* We have to actually move the cursor */
232 SetCursorPos( PosX, PosY );
237 if ( dwFlags & MOUSEEVENTF_MOVE )
239 hardware_event( WM_MOUSEMOVE,
240 keyState, 0L, PosX, PosY, time, extra );
242 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN) )
244 MouseButtonsStates[0] = AsyncMouseButtonsStates[0] = TRUE;
245 hardware_event( WM_LBUTTONDOWN,
246 keyState, 0L, PosX, PosY, time, extra );
248 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP) )
250 MouseButtonsStates[0] = FALSE;
251 hardware_event( WM_LBUTTONUP,
252 keyState, 0L, PosX, PosY, time, extra );
254 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN) )
256 MouseButtonsStates[2] = AsyncMouseButtonsStates[2] = TRUE;
257 hardware_event( WM_RBUTTONDOWN,
258 keyState, 0L, PosX, PosY, time, extra );
260 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_LEFTUP) )
262 MouseButtonsStates[2] = FALSE;
263 hardware_event( WM_RBUTTONUP,
264 keyState, 0L, PosX, PosY, time, extra );
266 if ( dwFlags & MOUSEEVENTF_MIDDLEDOWN )
268 MouseButtonsStates[1] = AsyncMouseButtonsStates[1] = TRUE;
269 hardware_event( WM_MBUTTONDOWN,
270 keyState, 0L, PosX, PosY, time, extra );
272 if ( dwFlags & MOUSEEVENTF_MIDDLEUP )
274 MouseButtonsStates[1] = FALSE;
275 hardware_event( WM_MBUTTONUP,
276 keyState, 0L, PosX, PosY, time, extra );
280 /***********************************************************************
281 * WIN16_mouse_event (USER.299)
283 void WINAPI WIN16_mouse_event( CONTEXT86 *context )
285 mouse_event( AX_reg(context), BX_reg(context), CX_reg(context),
286 DX_reg(context), MAKELONG(SI_reg(context), DI_reg(context)) );
289 /***********************************************************************
290 * GetMouseEventProc (USER.337)
292 FARPROC16 WINAPI GetMouseEventProc16(void)
294 HMODULE16 hmodule = GetModuleHandle16("USER");
295 return NE_GetEntryPoint( hmodule, NE_GetOrdinal( hmodule, "mouse_event" ));
299 /**********************************************************************
300 * EnableHardwareInput (USER.331)
302 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
304 BOOL16 bOldState = InputEnabled;
305 FIXME_(event)("(%d) - stub\n", bEnable);
306 InputEnabled = bEnable;
311 /***********************************************************************
312 * SwapMouseButton16 (USER.186)
314 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
316 BOOL16 ret = SwappedButtons;
317 SwappedButtons = fSwap;
322 /***********************************************************************
323 * SwapMouseButton (USER32.537)
325 BOOL WINAPI SwapMouseButton( BOOL fSwap )
327 BOOL ret = SwappedButtons;
328 SwappedButtons = fSwap;
332 /**********************************************************************
335 * We need this to be able to generate double click messages
336 * when menu code captures mouse in the window without CS_DBLCLK style.
338 HWND EVENT_Capture(HWND hwnd, INT16 ht)
340 HWND capturePrev = 0, captureWnd = 0;
341 MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0;
345 /* Get the messageQ for the current thread */
346 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
348 WARN_(win)("\tCurrent message queue not found. Exiting!\n" );
352 /* Get the current capture window from the perQ data of the current message Q */
353 capturePrev = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
362 wndPtr = WIN_FindWndPtr( hwnd );
365 TRACE_(win)("(0x%04x)\n", hwnd );
371 /* Update the perQ capture window and send messages */
372 if( capturePrev != captureWnd )
376 /* Retrieve the message queue associated with this window */
377 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
380 WARN_(win)("\tMessage queue not found. Exiting!\n" );
384 /* Make sure that message queue for the window we are setting capture to
385 * shares the same perQ data as the current threads message queue.
387 if ( pCurMsgQ->pQData != pMsgQ->pQData )
391 PERQDATA_SetCaptureWnd( pCurMsgQ->pQData, captureWnd );
392 PERQDATA_SetCaptureInfo( pCurMsgQ->pQData, captureHT );
396 WND* wndPtr = WIN_FindWndPtr( capturePrev );
397 if( wndPtr && (wndPtr->flags & WIN_ISWIN32) )
398 SendMessageA( capturePrev, WM_CAPTURECHANGED, 0L, hwnd);
399 WIN_ReleaseWndPtr(wndPtr);
404 /* Unlock the queues before returning */
406 QUEUE_Unlock( pMsgQ );
408 QUEUE_Unlock( pCurMsgQ );
410 WIN_ReleaseWndPtr(wndPtr);
415 /**********************************************************************
416 * SetCapture16 (USER.18)
418 HWND16 WINAPI SetCapture16( HWND16 hwnd )
420 return (HWND16)EVENT_Capture( hwnd, HTCLIENT );
424 /**********************************************************************
425 * SetCapture (USER32.464)
427 HWND WINAPI SetCapture( HWND hwnd )
429 return EVENT_Capture( hwnd, HTCLIENT );
433 /**********************************************************************
434 * ReleaseCapture (USER.19) (USER32.439)
436 BOOL WINAPI ReleaseCapture(void)
438 return (EVENT_Capture( 0, 0 ) != 0);
442 /**********************************************************************
443 * GetCapture16 (USER.236)
445 HWND16 WINAPI GetCapture16(void)
447 return (HWND16)GetCapture();
450 /**********************************************************************
451 * GetCapture (USER32.208)
453 HWND WINAPI GetCapture(void)
455 MESSAGEQUEUE *pCurMsgQ = 0;
456 HWND hwndCapture = 0;
458 /* Get the messageQ for the current thread */
459 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
461 TRACE_(win)("GetCapture32: Current message queue not found. Exiting!\n" );
465 /* Get the current capture window from the perQ data of the current message Q */
466 hwndCapture = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
468 QUEUE_Unlock( pCurMsgQ );
472 /**********************************************************************
473 * GetKeyState (USER.106)
475 INT16 WINAPI GetKeyState16(INT16 vkey)
477 return GetKeyState(vkey);
480 /**********************************************************************
481 * GetKeyState (USER32.249)
483 * An application calls the GetKeyState function in response to a
484 * keyboard-input message. This function retrieves the state of the key
485 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
487 SHORT WINAPI GetKeyState(INT vkey)
493 case VK_LBUTTON : /* VK_LBUTTON is 1 */
494 retval = MouseButtonsStates[0] ? 0x8000 : 0;
496 case VK_MBUTTON : /* VK_MBUTTON is 4 */
497 retval = MouseButtonsStates[1] ? 0x8000 : 0;
499 case VK_RBUTTON : /* VK_RBUTTON is 2 */
500 retval = MouseButtonsStates[2] ? 0x8000 : 0;
503 if (vkey >= 'a' && vkey <= 'z')
505 retval = ( (WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
506 (WORD)(QueueKeyStateTable[vkey] & 0x01);
508 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
512 /**********************************************************************
513 * GetKeyboardState (USER.222)(USER32.254)
515 * An application calls the GetKeyboardState function in response to a
516 * keyboard-input message. This function retrieves the state of the keyboard
517 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
519 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
521 TRACE_(key)("(%p)\n", lpKeyState);
522 if (lpKeyState != NULL) {
523 QueueKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
524 QueueKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
525 QueueKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
526 memcpy(lpKeyState, QueueKeyStateTable, 256);
532 /**********************************************************************
533 * SetKeyboardState (USER.223)(USER32.484)
535 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
537 TRACE_(key)("(%p)\n", lpKeyState);
538 if (lpKeyState != NULL) {
539 memcpy(QueueKeyStateTable, lpKeyState, 256);
540 MouseButtonsStates[0] = (QueueKeyStateTable[VK_LBUTTON] != 0);
541 MouseButtonsStates[1] = (QueueKeyStateTable[VK_MBUTTON] != 0);
542 MouseButtonsStates[2] = (QueueKeyStateTable[VK_RBUTTON] != 0);
548 /**********************************************************************
549 * GetAsyncKeyState (USER32.207)
551 * Determine if a key is or was pressed. retval has high-order
552 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
555 * This uses the variable AsyncMouseButtonsStates and
556 * AsyncKeyStateTable (set in event.c) which have the mouse button
557 * number or key number (whichever is applicable) set to true if the
558 * mouse or key had been depressed since the last call to
561 WORD WINAPI GetAsyncKeyState(INT nKey)
567 retval = (AsyncMouseButtonsStates[0] ? 0x0001 : 0) |
568 (MouseButtonsStates[0] ? 0x8000 : 0);
571 retval = (AsyncMouseButtonsStates[1] ? 0x0001 : 0) |
572 (MouseButtonsStates[1] ? 0x8000 : 0);
575 retval = (AsyncMouseButtonsStates[2] ? 0x0001 : 0) |
576 (MouseButtonsStates[2] ? 0x8000 : 0);
579 retval = AsyncKeyStateTable[nKey] |
580 ((InputKeyStateTable[nKey] & 0x80) ? 0x8000 : 0);
584 /* all states to false */
585 memset( AsyncMouseButtonsStates, 0, sizeof(AsyncMouseButtonsStates) );
586 memset( AsyncKeyStateTable, 0, sizeof(AsyncKeyStateTable) );
588 TRACE_(key)("(%x) -> %x\n", nKey, retval);
592 /**********************************************************************
593 * GetAsyncKeyState16 (USER.249)
595 WORD WINAPI GetAsyncKeyState16(INT16 nKey)
597 return GetAsyncKeyState(nKey);
600 /***********************************************************************
601 * IsUserIdle (USER.333)
603 BOOL16 WINAPI IsUserIdle16(void)
605 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
608 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
611 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
614 /* Should check for screen saver activation here ... */
619 /**********************************************************************
620 * KBD_translate_accelerator
622 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
624 static BOOL KBD_translate_accelerator(HWND hWnd,LPMSG msg,
625 BYTE fVirt,WORD key,WORD cmd)
627 BOOL sendmsg = FALSE;
629 if(msg->wParam == key)
631 if (msg->message == WM_CHAR) {
632 if ( !(fVirt & FALT) && !(fVirt & FVIRTKEY) )
634 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n",
639 if(fVirt & FVIRTKEY) {
641 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
642 msg->wParam,0xff & HIWORD(msg->lParam));
643 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
644 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
645 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
646 if(mask == (fVirt & (FSHIFT | FCONTROL | FALT)))
649 TRACE_(accel)(", but incorrect SHIFT/CTRL/ALT-state\n");
653 if (!(msg->lParam & 0x01000000)) /* no special_key */
655 if ((fVirt & FALT) && (msg->lParam & 0x20000000))
656 { /* ^^ ALT pressed */
657 TRACE_(accel)("found accel for Alt-%c\n", msg->wParam&0xff);
664 if (sendmsg) /* found an accelerator, but send a message... ? */
666 INT16 iSysStat,iStat,mesg=0;
669 if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
675 if (!IsWindowEnabled(hWnd))
679 WND* wndPtr = WIN_FindWndPtr(hWnd);
681 hMenu = (wndPtr->dwStyle & WS_CHILD) ? 0 : (HMENU)wndPtr->wIDmenu;
682 iSysStat = (wndPtr->hSysMenu) ? GetMenuState(GetSubMenu16(wndPtr->hSysMenu, 0),
683 cmd, MF_BYCOMMAND) : -1 ;
684 iStat = (hMenu) ? GetMenuState(hMenu,
685 cmd, MF_BYCOMMAND) : -1 ;
687 WIN_ReleaseWndPtr(wndPtr);
691 if (iSysStat & (MF_DISABLED|MF_GRAYED))
704 if (iStat & (MF_DISABLED|MF_GRAYED))
714 if( mesg==WM_COMMAND ) {
715 TRACE_(accel)(", sending WM_COMMAND, wParam=%0x\n", 0x10000 | cmd);
716 SendMessageA(hWnd, mesg, 0x10000 | cmd, 0L);
717 } else if( mesg==WM_SYSCOMMAND ) {
718 TRACE_(accel)(", sending WM_SYSCOMMAND, wParam=%0x\n", cmd);
719 SendMessageA(hWnd, mesg, cmd, 0x00010000L);
723 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
724 * #0: unknown (please report!)
725 * #1: for WM_KEYUP,WM_SYSKEYUP
726 * #2: mouse is captured
727 * #3: window is disabled
728 * #4: it's a disabled system menu option
729 * #5: it's a menu option, but window is iconic
730 * #6: it's a menu option, but disabled
732 TRACE_(accel)(", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg);
734 ERR_(accel)(" unknown reason - please report!");
742 /**********************************************************************
743 * TranslateAccelerator (USER32.551)(USER32.552)(USER32.553)
745 INT WINAPI TranslateAccelerator(HWND hWnd, HACCEL hAccel, LPMSG msg)
748 LPACCEL16 lpAccelTbl;
753 WARN_(accel)("msg null; should hang here to be win compatible\n");
756 if (!hAccel || !(lpAccelTbl = (LPACCEL16) LockResource16(hAccel)))
758 WARN_(accel)("invalid accel handle=%x\n", hAccel);
761 if ((msg->message != WM_KEYDOWN &&
762 msg->message != WM_KEYUP &&
763 msg->message != WM_SYSKEYDOWN &&
764 msg->message != WM_SYSKEYUP &&
765 msg->message != WM_CHAR)) return 0;
767 TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,"
768 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%lx\n",
769 hAccel,hWnd,msg->hwnd,msg->message,msg->wParam,msg->lParam);
774 if (KBD_translate_accelerator(hWnd,msg,lpAccelTbl[i].fVirt,
775 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
777 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
778 WARN_(accel)("couldn't translate accelerator key\n");
782 /**********************************************************************
783 * TranslateAccelerator16 (USER.178)
785 INT16 WINAPI TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
787 LPACCEL16 lpAccelTbl;
793 WARN_(accel)("msg null; should hang here to be win compatible\n");
796 if (!hAccel || !(lpAccelTbl = (LPACCEL16) LockResource16(hAccel)))
798 WARN_(accel)("invalid accel handle=%x\n", hAccel);
801 if ((msg->message != WM_KEYDOWN &&
802 msg->message != WM_KEYUP &&
803 msg->message != WM_SYSKEYDOWN &&
804 msg->message != WM_SYSKEYUP &&
805 msg->message != WM_CHAR)) return 0;
807 TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,\
808 msg->hwnd=%04x, msg->message=%04x, wParam=%04x, lParam=%lx\n", hAccel,hWnd,msg->hwnd,msg->message,msg->wParam,msg->lParam);
810 STRUCT32_MSG16to32(msg,&msg32);
815 if (KBD_translate_accelerator(hWnd,&msg32,lpAccelTbl[i].fVirt,
816 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
818 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
819 WARN_(accel)("couldn't translate accelerator key\n");
824 /**********************************************************************
825 * VkKeyScanA (USER32.573)
827 WORD WINAPI VkKeyScanA(CHAR cChar)
829 return VkKeyScan16(cChar);
832 /******************************************************************************
833 * VkKeyScanW (USER32.576)
835 WORD WINAPI VkKeyScanW(WCHAR cChar)
837 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
840 /**********************************************************************
841 * VkKeyScanExA (USER32.574)
843 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
845 /* FIXME: complete workaround this is */
846 return VkKeyScan16(cChar);
849 /******************************************************************************
850 * VkKeyScanExW (USER32.575)
852 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
854 /* FIXME: complete workaround this is */
855 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
858 /******************************************************************************
859 * GetKeyboardType (USER32.255)
861 INT WINAPI GetKeyboardType(INT nTypeFlag)
863 return GetKeyboardType16(nTypeFlag);
866 /******************************************************************************
867 * MapVirtualKeyA (USER32.383)
869 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
871 return MapVirtualKey16(code,maptype);
874 /******************************************************************************
875 * MapVirtualKeyW (USER32.385)
877 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
879 return MapVirtualKey16(code,maptype);
882 /******************************************************************************
883 * MapVirtualKeyExA (USER32.384)
885 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
888 FIXME_(keyboard)("(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
889 return MapVirtualKey16(code,maptype);
892 /****************************************************************************
893 * GetKBCodePage (USER32.246)
895 UINT WINAPI GetKBCodePage(void)
897 return GetKBCodePage16();
900 /****************************************************************************
901 * GetKeyboardLayoutName16 (USER.477)
903 INT16 WINAPI GetKeyboardLayoutName16(LPSTR pwszKLID)
905 return GetKeyboardLayoutNameA(pwszKLID);
908 /***********************************************************************
909 * GetKeyboardLayout (USER32.250)
911 * FIXME: - device handle for keyboard layout defaulted to
912 * the language id. This is the way Windows default works.
913 * - the thread identifier (dwLayout) is also ignored.
915 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
918 layout = GetSystemDefaultLCID(); /* FIXME */
919 layout |= (layout<<16); /* FIXME */
920 TRACE_(keyboard)("returning %08x\n",layout);
924 /****************************************************************************
925 * GetKeyboardLayoutNameA (USER32.252)
927 INT WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID)
929 sprintf(pwszKLID, "%08x",GetKeyboardLayout(0));
933 /****************************************************************************
934 * GetKeyboardLayoutNameW (USER32.253)
936 INT WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
938 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
939 int res = GetKeyboardLayoutNameA(buf);
940 lstrcpyAtoW(pwszKLID,buf);
941 HeapFree( GetProcessHeap(), 0, buf );
945 /****************************************************************************
946 * GetKeyNameTextA (USER32.247)
948 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
950 return GetKeyNameText16(lParam,lpBuffer,nSize);
953 /****************************************************************************
954 * GetKeyNameTextW (USER32.248)
956 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
958 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, nSize );
959 int res = GetKeyNameTextA(lParam,buf,nSize);
961 lstrcpynAtoW(lpBuffer,buf,nSize);
962 HeapFree( GetProcessHeap(), 0, buf );
966 /****************************************************************************
967 * ToAscii (USER32.546)
969 INT WINAPI ToAscii( UINT virtKey,UINT scanCode,LPBYTE lpKeyState,
970 LPWORD lpChar,UINT flags )
972 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
975 /****************************************************************************
976 * ToAsciiEx (USER32.547)
978 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
979 LPWORD lpChar, UINT flags, HKL dwhkl )
981 /* FIXME: need true implementation */
982 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
985 /**********************************************************************
986 * ActivateKeyboardLayout (USER32.1)
988 * Call ignored. WINE supports only system default keyboard layout.
990 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
992 TRACE_(keyboard)("(%d, %d)\n", hLayout, flags);
993 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
998 /***********************************************************************
999 * GetKeyboardLayoutList (USER32.251)
1001 * FIXME: Supports only the system default language and layout and
1002 * returns only 1 value.
1004 * Return number of values available if either input parm is
1005 * 0, per MS documentation.
1008 INT WINAPI GetKeyboardLayoutList(INT nBuff,HKL *layouts)
1010 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
1011 if (!nBuff || !layouts)
1014 layouts[0] = GetKeyboardLayout(0);
1019 /***********************************************************************
1020 * RegisterHotKey (USER32.433)
1022 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk) {
1023 FIXME_(keyboard)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
1027 /***********************************************************************
1028 * UnregisterHotKey (USER32.565)
1030 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id) {
1031 FIXME_(keyboard)("(0x%08x,%d): stub\n",hwnd,id);
1036 /***********************************************************************
1037 * ToUnicode (USER32.548)
1039 INT WINAPI ToUnicode(
1047 FIXME_(keyboard)(": stub\n");
1051 /***********************************************************************
1052 * LoadKeyboardLayoutA (USER32.367)
1053 * Call ignored. WINE supports only system default keyboard layout.
1055 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
1057 TRACE_(keyboard)("(%s, %d)\n", pwszKLID, Flags);
1058 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
1062 /***********************************************************************
1063 * LoadKeyboardLayoutW (USER32.368)
1065 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
1067 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
1069 lstrcpynWtoA(buf,pwszKLID,8);
1071 res = LoadKeyboardLayoutA(buf, Flags);
1072 HeapFree( GetProcessHeap(), 0, buf );