Release 990226.
[wine/gsoc-2012-control.git] / windows / input.c
blob8fd22a260da948e22db620d18bf15fb29d1f9ad4
1 /*
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
12 #include <stdlib.h>
13 #include <string.h>
14 #include <ctype.h>
15 #include <assert.h>
17 #include "winuser.h"
18 #include "wine/winbase16.h"
19 #include "wine/winuser16.h"
20 #include "wine/keyboard16.h"
21 #include "win.h"
22 #include "gdi.h"
23 #include "heap.h"
24 #include "input.h"
25 #include "keyboard.h"
26 #include "mouse.h"
27 #include "message.h"
28 #include "sysmetrics.h"
29 #include "debug.h"
30 #include "debugtools.h"
31 #include "struct32.h"
32 #include "winerror.h"
33 #include "task.h"
35 static BOOL InputEnabled = TRUE;
36 static BOOL SwappedButtons = FALSE;
38 BOOL MouseButtonsStates[3];
39 BOOL AsyncMouseButtonsStates[3];
40 BYTE InputKeyStateTable[256];
41 BYTE QueueKeyStateTable[256];
42 BYTE AsyncKeyStateTable[256];
44 typedef union
46 struct
48 unsigned long count : 16;
49 unsigned long code : 8;
50 unsigned long extended : 1;
51 unsigned long unused : 2;
52 unsigned long win_internal : 2;
53 unsigned long context : 1;
54 unsigned long previous : 1;
55 unsigned long transition : 1;
56 } lp1;
57 unsigned long lp2;
58 } KEYLP;
60 /***********************************************************************
61 * keybd_event (USER32.583)
63 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
64 DWORD dwFlags, DWORD dwExtraInfo )
66 DWORD posX, posY, time, extra;
67 WORD message;
68 KEYLP keylp;
69 keylp.lp2 = 0;
71 if (!InputEnabled) return;
74 * If we are called by the Wine keyboard driver, use the additional
75 * info pointed to by the dwExtraInfo argument.
76 * Otherwise, we need to determine that info ourselves (probably
77 * less accurate, but we can't help that ...).
79 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_KEYBDEVENT) )
80 && ((WINE_KEYBDEVENT *)dwExtraInfo)->magic == WINE_KEYBDEVENT_MAGIC )
82 WINE_KEYBDEVENT *wke = (WINE_KEYBDEVENT *)dwExtraInfo;
83 posX = wke->posX;
84 posY = wke->posY;
85 time = wke->time;
86 extra = 0;
88 else
90 DWORD keyState;
91 time = GetTickCount();
92 extra = dwExtraInfo;
94 if ( !EVENT_QueryPointer( &posX, &posY, &keyState ))
95 return;
99 keylp.lp1.count = 1;
100 keylp.lp1.code = bScan;
101 keylp.lp1.extended = (dwFlags & KEYEVENTF_EXTENDEDKEY) != 0;
102 keylp.lp1.win_internal = 0; /* this has something to do with dialogs,
103 * don't remember where I read it - AK */
104 /* it's '1' under windows, when a dialog box appears
105 * and you press one of the underlined keys - DF*/
107 if ( dwFlags & KEYEVENTF_KEYUP )
109 BOOL sysKey = (InputKeyStateTable[VK_MENU] & 0x80)
110 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
111 && !(dwFlags & KEYEVENTF_WINE_FORCEEXTENDED); /* for Alt from AltGr */
113 InputKeyStateTable[bVk] &= ~0x80;
114 keylp.lp1.previous = 1;
115 keylp.lp1.transition = 1;
116 message = sysKey ? WM_SYSKEYUP : WM_KEYUP;
118 else
120 keylp.lp1.previous = (InputKeyStateTable[bVk] & 0x80) != 0;
121 keylp.lp1.transition = 0;
123 if (!(InputKeyStateTable[bVk] & 0x80))
124 InputKeyStateTable[bVk] ^= 0x01;
125 InputKeyStateTable[bVk] |= 0x80;
127 message = (InputKeyStateTable[VK_MENU] & 0x80)
128 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
129 ? WM_SYSKEYDOWN : WM_KEYDOWN;
132 if ( message == WM_SYSKEYDOWN || message == WM_SYSKEYUP )
133 keylp.lp1.context = (InputKeyStateTable[VK_MENU] & 0x80) != 0; /* 1 if alt */
136 TRACE(key, " wParam=%04X, lParam=%08lX\n", bVk, keylp.lp2 );
137 TRACE(key, " InputKeyState=%X\n", InputKeyStateTable[bVk] );
139 hardware_event( message, bVk, keylp.lp2, posX, posY, time, extra );
142 /***********************************************************************
143 * mouse_event (USER32.584)
145 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
146 DWORD cButtons, DWORD dwExtraInfo )
148 DWORD posX, posY, keyState, time, extra;
150 if (!InputEnabled) return;
153 * If we are called by the Wine mouse driver, use the additional
154 * info pointed to by the dwExtraInfo argument.
155 * Otherwise, we need to determine that info ourselves (probably
156 * less accurate, but we can't help that ...).
158 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_MOUSEEVENT) )
159 && ((WINE_MOUSEEVENT *)dwExtraInfo)->magic == WINE_MOUSEEVENT_MAGIC )
161 WINE_MOUSEEVENT *wme = (WINE_MOUSEEVENT *)dwExtraInfo;
162 keyState = wme->keyState;
163 time = wme->time;
164 extra = (DWORD)wme->hWnd;
166 assert( dwFlags & MOUSEEVENTF_ABSOLUTE );
167 posX = (dx * SYSMETRICS_CXSCREEN) >> 16;
168 posY = (dy * SYSMETRICS_CYSCREEN) >> 16;
170 else
172 time = GetTickCount();
173 extra = dwExtraInfo;
175 if ( !EVENT_QueryPointer( &posX, &posY, &keyState ))
176 return;
178 if ( dwFlags & MOUSEEVENTF_MOVE )
180 if ( dwFlags & MOUSEEVENTF_ABSOLUTE )
182 posX = (dx * SYSMETRICS_CXSCREEN) >> 16;
183 posY = (dy * SYSMETRICS_CYSCREEN) >> 16;
185 else
187 posX += dx;
188 posY += dy;
190 /* We have to actually move the cursor */
191 SetCursorPos( posX, posY );
195 if ( dwFlags & MOUSEEVENTF_MOVE )
197 hardware_event( WM_MOUSEMOVE,
198 keyState, 0L, posX, posY, time, extra );
200 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN) )
202 MouseButtonsStates[0] = AsyncMouseButtonsStates[0] = TRUE;
203 hardware_event( WM_LBUTTONDOWN,
204 keyState, 0L, posX, posY, time, extra );
206 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP) )
208 MouseButtonsStates[0] = FALSE;
209 hardware_event( WM_LBUTTONUP,
210 keyState, 0L, posX, posY, time, extra );
212 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN) )
214 MouseButtonsStates[2] = AsyncMouseButtonsStates[2] = TRUE;
215 hardware_event( WM_RBUTTONDOWN,
216 keyState, 0L, posX, posY, time, extra );
218 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_LEFTUP) )
220 MouseButtonsStates[2] = FALSE;
221 hardware_event( WM_RBUTTONUP,
222 keyState, 0L, posX, posY, time, extra );
224 if ( dwFlags & MOUSEEVENTF_MIDDLEDOWN )
226 MouseButtonsStates[1] = AsyncMouseButtonsStates[1] = TRUE;
227 hardware_event( WM_MBUTTONDOWN,
228 keyState, 0L, posX, posY, time, extra );
230 if ( dwFlags & MOUSEEVENTF_MIDDLEUP )
232 MouseButtonsStates[1] = FALSE;
233 hardware_event( WM_MBUTTONUP,
234 keyState, 0L, posX, posY, time, extra );
238 /**********************************************************************
239 * EnableHardwareInput (USER.331)
241 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
243 BOOL16 bOldState = InputEnabled;
244 FIXME(event,"(%d) - stub\n", bEnable);
245 InputEnabled = bEnable;
246 return bOldState;
250 /***********************************************************************
251 * SwapMouseButton16 (USER.186)
253 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
255 BOOL16 ret = SwappedButtons;
256 SwappedButtons = fSwap;
257 return ret;
261 /***********************************************************************
262 * SwapMouseButton32 (USER32.537)
264 BOOL WINAPI SwapMouseButton( BOOL fSwap )
266 BOOL ret = SwappedButtons;
267 SwappedButtons = fSwap;
268 return ret;
271 /**********************************************************************
272 * EVENT_Capture
274 * We need this to be able to generate double click messages
275 * when menu code captures mouse in the window without CS_DBLCLK style.
277 HWND EVENT_Capture(HWND hwnd, INT16 ht)
279 HWND capturePrev = 0, captureWnd = 0;
280 MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0;
281 WND* wndPtr = 0;
282 INT16 captureHT = 0;
284 /* Get the messageQ for the current thread */
285 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
287 WARN( win, "\tCurrent message queue not found. Exiting!\n" );
288 goto CLEANUP;
291 /* Get the current capture window from the perQ data of the current message Q */
292 capturePrev = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
294 if (!hwnd)
296 captureWnd = 0L;
297 captureHT = 0;
299 else
301 wndPtr = WIN_FindWndPtr( hwnd );
302 if (wndPtr)
304 TRACE(win, "(0x%04x)\n", hwnd );
305 captureWnd = hwnd;
306 captureHT = ht;
310 /* Update the perQ capture window and send messages */
311 if( capturePrev != captureWnd )
313 if (wndPtr)
315 /* Retrieve the message queue associated with this window */
316 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
317 if ( !pMsgQ )
319 WARN( win, "\tMessage queue not found. Exiting!\n" );
320 goto CLEANUP;
323 /* Make sure that message queue for the window we are setting capture to
324 * shares the same perQ data as the current threads message queue.
326 if ( pCurMsgQ->pQData != pMsgQ->pQData )
327 goto CLEANUP;
330 PERQDATA_SetCaptureWnd( pCurMsgQ->pQData, captureWnd );
331 PERQDATA_SetCaptureInfo( pCurMsgQ->pQData, captureHT );
333 if( capturePrev )
335 WND* wndPtr = WIN_FindWndPtr( capturePrev );
336 if( wndPtr && (wndPtr->flags & WIN_ISWIN32) )
337 SendMessageA( capturePrev, WM_CAPTURECHANGED, 0L, hwnd);
341 CLEANUP:
342 /* Unlock the queues before returning */
343 if ( pMsgQ )
344 QUEUE_Unlock( pMsgQ );
345 if ( pCurMsgQ )
346 QUEUE_Unlock( pCurMsgQ );
348 return capturePrev;
352 /**********************************************************************
353 * SetCapture16 (USER.18)
355 HWND16 WINAPI SetCapture16( HWND16 hwnd )
357 return (HWND16)EVENT_Capture( hwnd, HTCLIENT );
361 /**********************************************************************
362 * SetCapture32 (USER32.464)
364 HWND WINAPI SetCapture( HWND hwnd )
366 return EVENT_Capture( hwnd, HTCLIENT );
370 /**********************************************************************
371 * ReleaseCapture (USER.19) (USER32.439)
373 void WINAPI ReleaseCapture(void)
375 EVENT_Capture( 0, 0 );
379 /**********************************************************************
380 * GetCapture16 (USER.236)
382 HWND16 WINAPI GetCapture16(void)
384 return (HWND16)GetCapture();
387 /**********************************************************************
388 * GetCapture32 (USER32.208)
390 HWND WINAPI GetCapture(void)
392 MESSAGEQUEUE *pCurMsgQ = 0;
393 HWND hwndCapture = 0;
395 /* Get the messageQ for the current thread */
396 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
398 TRACE( win, "GetCapture32: Current message queue not found. Exiting!\n" );
399 return 0;
402 /* Get the current capture window from the perQ data of the current message Q */
403 hwndCapture = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
405 QUEUE_Unlock( pCurMsgQ );
406 return hwndCapture;
409 /**********************************************************************
410 * GetKeyState (USER.106)
412 INT16 WINAPI GetKeyState16(INT16 vkey)
414 return GetKeyState(vkey);
417 /**********************************************************************
418 * GetKeyState (USER32.249)
420 * An application calls the GetKeyState function in response to a
421 * keyboard-input message. This function retrieves the state of the key
422 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
424 INT16 WINAPI GetKeyState(INT vkey)
426 INT retval;
428 switch (vkey)
430 case VK_LBUTTON : /* VK_LBUTTON is 1 */
431 retval = MouseButtonsStates[0] ? 0x8000 : 0;
432 break;
433 case VK_MBUTTON : /* VK_MBUTTON is 4 */
434 retval = MouseButtonsStates[1] ? 0x8000 : 0;
435 break;
436 case VK_RBUTTON : /* VK_RBUTTON is 2 */
437 retval = MouseButtonsStates[2] ? 0x8000 : 0;
438 break;
439 default :
440 if (vkey >= 'a' && vkey <= 'z')
441 vkey += 'A' - 'a';
442 retval = ( (WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
443 (WORD)(QueueKeyStateTable[vkey] & 0x01);
445 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
446 return retval;
449 /**********************************************************************
450 * GetKeyboardState (USER.222)(USER32.254)
452 * An application calls the GetKeyboardState function in response to a
453 * keyboard-input message. This function retrieves the state of the keyboard
454 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
456 VOID WINAPI GetKeyboardState(LPBYTE lpKeyState)
458 TRACE(key, "(%p)\n", lpKeyState);
459 if (lpKeyState != NULL) {
460 QueueKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
461 QueueKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
462 QueueKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
463 memcpy(lpKeyState, QueueKeyStateTable, 256);
467 /**********************************************************************
468 * SetKeyboardState (USER.223)(USER32.484)
470 VOID WINAPI SetKeyboardState(LPBYTE lpKeyState)
472 TRACE(key, "(%p)\n", lpKeyState);
473 if (lpKeyState != NULL) {
474 memcpy(QueueKeyStateTable, lpKeyState, 256);
475 MouseButtonsStates[0] = (QueueKeyStateTable[VK_LBUTTON] != 0);
476 MouseButtonsStates[1] = (QueueKeyStateTable[VK_MBUTTON] != 0);
477 MouseButtonsStates[2] = (QueueKeyStateTable[VK_RBUTTON] != 0);
481 /**********************************************************************
482 * GetAsyncKeyState32 (USER32.207)
484 * Determine if a key is or was pressed. retval has high-order
485 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
486 * been pressed.
488 * This uses the variable AsyncMouseButtonsStates and
489 * AsyncKeyStateTable (set in event.c) which have the mouse button
490 * number or key number (whichever is applicable) set to true if the
491 * mouse or key had been depressed since the last call to
492 * GetAsyncKeyState.
494 WORD WINAPI GetAsyncKeyState(INT nKey)
496 short retval;
498 switch (nKey) {
499 case VK_LBUTTON:
500 retval = (AsyncMouseButtonsStates[0] ? 0x0001 : 0) |
501 (MouseButtonsStates[0] ? 0x8000 : 0);
502 break;
503 case VK_MBUTTON:
504 retval = (AsyncMouseButtonsStates[1] ? 0x0001 : 0) |
505 (MouseButtonsStates[1] ? 0x8000 : 0);
506 break;
507 case VK_RBUTTON:
508 retval = (AsyncMouseButtonsStates[2] ? 0x0001 : 0) |
509 (MouseButtonsStates[2] ? 0x8000 : 0);
510 break;
511 default:
512 retval = AsyncKeyStateTable[nKey] |
513 ((InputKeyStateTable[nKey] & 0x80) ? 0x8000 : 0);
514 break;
517 /* all states to false */
518 memset( AsyncMouseButtonsStates, 0, sizeof(AsyncMouseButtonsStates) );
519 memset( AsyncKeyStateTable, 0, sizeof(AsyncKeyStateTable) );
521 TRACE(key, "(%x) -> %x\n", nKey, retval);
522 return retval;
525 /**********************************************************************
526 * GetAsyncKeyState16 (USER.249)
528 WORD WINAPI GetAsyncKeyState16(INT16 nKey)
530 return GetAsyncKeyState(nKey);
533 /**********************************************************************
534 * KBD_translate_accelerator
536 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
538 static BOOL KBD_translate_accelerator(HWND hWnd,LPMSG msg,
539 BYTE fVirt,WORD key,WORD cmd)
541 BOOL sendmsg = FALSE;
543 if(msg->wParam == key)
545 if (msg->message == WM_CHAR) {
546 if ( !(fVirt & FALT) && !(fVirt & FVIRTKEY) )
548 TRACE(accel,"found accel for WM_CHAR: ('%c')\n",
549 msg->wParam&0xff);
550 sendmsg=TRUE;
552 } else {
553 if(fVirt & FVIRTKEY) {
554 INT mask = 0;
555 TRACE(accel,"found accel for virt_key %04x (scan %04x)\n",
556 msg->wParam,0xff & HIWORD(msg->lParam));
557 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
558 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
559 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
560 if(mask == (fVirt & (FSHIFT | FCONTROL | FALT)))
561 sendmsg=TRUE;
562 else
563 TRACE(accel,", but incorrect SHIFT/CTRL/ALT-state\n");
565 else
567 if (!(msg->lParam & 0x01000000)) /* no special_key */
569 if ((fVirt & FALT) && (msg->lParam & 0x20000000))
570 { /* ^^ ALT pressed */
571 TRACE(accel,"found accel for Alt-%c\n", msg->wParam&0xff);
572 sendmsg=TRUE;
578 if (sendmsg) /* found an accelerator, but send a message... ? */
580 INT16 iSysStat,iStat,mesg=0;
581 HMENU16 hMenu;
583 if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
584 mesg=1;
585 else
586 if (GetCapture())
587 mesg=2;
588 else
589 if (!IsWindowEnabled(hWnd))
590 mesg=3;
591 else
593 WND* wndPtr = WIN_FindWndPtr(hWnd);
595 hMenu = (wndPtr->dwStyle & WS_CHILD) ? 0 : (HMENU)wndPtr->wIDmenu;
596 iSysStat = (wndPtr->hSysMenu) ? GetMenuState(GetSubMenu16(wndPtr->hSysMenu, 0),
597 cmd, MF_BYCOMMAND) : -1 ;
598 iStat = (hMenu) ? GetMenuState(hMenu,
599 cmd, MF_BYCOMMAND) : -1 ;
601 if (iSysStat!=-1)
603 if (iSysStat & (MF_DISABLED|MF_GRAYED))
604 mesg=4;
605 else
606 mesg=WM_SYSCOMMAND;
608 else
610 if (iStat!=-1)
612 if (IsIconic(hWnd))
613 mesg=5;
614 else
616 if (iStat & (MF_DISABLED|MF_GRAYED))
617 mesg=6;
618 else
619 mesg=WM_COMMAND;
622 else
623 mesg=WM_COMMAND;
626 if ( mesg==WM_COMMAND || mesg==WM_SYSCOMMAND )
628 TRACE(accel,", sending %s, wParam=%0x\n",
629 mesg==WM_COMMAND ? "WM_COMMAND" : "WM_SYSCOMMAND",
630 cmd);
631 SendMessageA(hWnd, mesg, cmd, 0x00010000L);
633 else
635 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
636 * #0: unknown (please report!)
637 * #1: for WM_KEYUP,WM_SYSKEYUP
638 * #2: mouse is captured
639 * #3: window is disabled
640 * #4: it's a disabled system menu option
641 * #5: it's a menu option, but window is iconic
642 * #6: it's a menu option, but disabled
644 TRACE(accel,", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg);
645 if(mesg==0)
646 ERR(accel, " unknown reason - please report!");
648 return TRUE;
651 return FALSE;
654 /**********************************************************************
655 * TranslateAccelerator32 (USER32.551)(USER32.552)(USER32.553)
657 INT WINAPI TranslateAccelerator(HWND hWnd, HACCEL hAccel, LPMSG msg)
659 /* YES, Accel16! */
660 LPACCEL16 lpAccelTbl = (LPACCEL16)LockResource16(hAccel);
661 int i;
663 TRACE(accel,"hwnd=0x%x hacc=0x%x msg=0x%x wp=0x%x lp=0x%lx\n", hWnd, hAccel, msg->message, msg->wParam, msg->lParam);
665 if (hAccel == 0 || msg == NULL ||
666 (msg->message != WM_KEYDOWN &&
667 msg->message != WM_KEYUP &&
668 msg->message != WM_SYSKEYDOWN &&
669 msg->message != WM_SYSKEYUP &&
670 msg->message != WM_CHAR)) {
671 WARN(accel, "erraneous input parameters\n");
672 SetLastError(ERROR_INVALID_PARAMETER);
673 return 0;
676 TRACE(accel, "TranslateAccelerators hAccel=%04x, hWnd=%04x,"
677 "msg->hwnd=%04x, msg->message=%04x\n",
678 hAccel,hWnd,msg->hwnd,msg->message);
680 i = 0;
683 if (KBD_translate_accelerator(hWnd,msg,lpAccelTbl[i].fVirt,
684 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
685 return 1;
686 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
687 WARN(accel, "couldn't translate accelerator key\n");
688 return 0;
691 /**********************************************************************
692 * TranslateAccelerator16 (USER.178)
694 INT16 WINAPI TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
696 LPACCEL16 lpAccelTbl = (LPACCEL16)LockResource16(hAccel);
697 int i;
698 MSG msg32;
700 if (hAccel == 0 || msg == NULL ||
701 (msg->message != WM_KEYDOWN &&
702 msg->message != WM_KEYUP &&
703 msg->message != WM_SYSKEYDOWN &&
704 msg->message != WM_SYSKEYUP &&
705 msg->message != WM_CHAR)) {
706 WARN(accel, "erraneous input parameters\n");
707 SetLastError(ERROR_INVALID_PARAMETER);
708 return 0;
711 TRACE(accel, "TranslateAccelerators hAccel=%04x, hWnd=%04x,\
712 msg->hwnd=%04x, msg->message=%04x\n", hAccel,hWnd,msg->hwnd,msg->message);
713 STRUCT32_MSG16to32(msg,&msg32);
716 i = 0;
719 if (KBD_translate_accelerator(hWnd,&msg32,lpAccelTbl[i].fVirt,
720 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
721 return 1;
722 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
723 WARN(accel, "couldn't translate accelerator key\n");
724 return 0;
728 /**********************************************************************
729 * VkKeyScanA (USER32.573)
731 WORD WINAPI VkKeyScanA(CHAR cChar)
733 return VkKeyScan16(cChar);
736 /******************************************************************************
737 * VkKeyScanW (USER32.576)
739 WORD WINAPI VkKeyScanW(WCHAR cChar)
741 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
744 /******************************************************************************
745 * GetKeyboardType32 (USER32.255)
747 INT WINAPI GetKeyboardType(INT nTypeFlag)
749 return GetKeyboardType16(nTypeFlag);
752 /******************************************************************************
753 * MapVirtualKey32A (USER32.383)
755 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
757 return MapVirtualKey16(code,maptype);
760 /******************************************************************************
761 * MapVirtualKey32W (USER32.385)
763 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
765 return MapVirtualKey16(code,maptype);
768 /******************************************************************************
769 * MapVirtualKeyEx32A (USER32.384)
771 UINT WINAPI MapVirtualKeyEx32A(UINT code, UINT maptype, HKL hkl)
773 if (hkl)
774 FIXME(keyboard,"(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
775 return MapVirtualKey16(code,maptype);
778 /****************************************************************************
779 * GetKBCodePage32 (USER32.246)
781 UINT WINAPI GetKBCodePage(void)
783 return GetKBCodePage16();
786 /****************************************************************************
787 * GetKeyboardLayoutName16 (USER.477)
789 INT16 WINAPI GetKeyboardLayoutName16(LPSTR pwszKLID)
791 return GetKeyboardLayoutNameA(pwszKLID);
794 /****************************************************************************
795 * GetKeyboardLayoutName32A (USER32.252)
797 INT WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID)
799 FIXME(keyboard,"always returns primary U.S. English layout\n");
800 strcpy(pwszKLID,"00000409");
801 return 1;
804 /****************************************************************************
805 * GetKeyboardLayoutName32W (USER32.253)
807 INT WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
809 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
810 int res = GetKeyboardLayoutNameA(buf);
811 lstrcpyAtoW(pwszKLID,buf);
812 HeapFree( GetProcessHeap(), 0, buf );
813 return res;
816 /****************************************************************************
817 * GetKeyNameText32A (USER32.247)
819 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
821 return GetKeyNameText16(lParam,lpBuffer,nSize);
824 /****************************************************************************
825 * GetKeyNameText32W (USER32.248)
827 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
829 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, nSize );
830 int res = GetKeyNameTextA(lParam,buf,nSize);
832 lstrcpynAtoW(lpBuffer,buf,nSize);
833 HeapFree( GetProcessHeap(), 0, buf );
834 return res;
837 /****************************************************************************
838 * ToAscii32 (USER32.546)
840 INT WINAPI ToAscii( UINT virtKey,UINT scanCode,LPBYTE lpKeyState,
841 LPWORD lpChar,UINT flags )
843 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
846 /***********************************************************************
847 * GetKeyboardLayout (USER32.250)
849 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
851 HKL layout;
852 FIXME(keyboard,"(%ld): stub\n",dwLayout);
853 layout = (0xcafe<<16)|GetSystemDefaultLCID(); /* FIXME */
854 TRACE(keyboard,"returning %x\n",layout);
855 return layout;
858 /**********************************************************************
859 * ActivateKeyboardLayout32 (USER32.1)
861 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
863 FIXME(keyboard, "(%d, %d): stub\n", hLayout, flags);
865 return 0;
869 /***********************************************************************
870 * GetKeyboardLayoutList (USER32.251)
871 * FIXME
873 INT WINAPI GetKeyboardLayoutList(INT nBuff,HKL *layouts)
875 FIXME(keyboard,"(%d,%p): stub\n",nBuff,layouts);
876 if (layouts)
877 layouts[0] = GetKeyboardLayout(0);
878 return 1;
882 /***********************************************************************
883 * RegisterHotKey (USER32.433)
885 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk) {
886 FIXME(keyboard,"(0x%08x,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
887 return TRUE;
890 /***********************************************************************
891 * UnregisterHotKey (USER32.565)
893 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id) {
894 FIXME(keyboard,"(0x%08x,%d): stub\n",hwnd,id);
895 return TRUE;
899 /***********************************************************************
900 * ToUnicode32 (USER32.548)
902 INT WINAPI ToUnicode(
903 UINT wVirtKey,
904 UINT wScanCode,
905 PBYTE lpKeyState,
906 LPWSTR pwszBuff,
907 int cchBuff,
908 UINT wFlags) {
910 FIXME(keyboard,": stub\n");
911 return 0;
914 /***********************************************************************
915 * LoadKeyboardLayout32A (USER32.367)
917 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
919 FIXME(keyboard, "%s, %d): stub\n", pwszKLID, Flags);
920 return 0;
923 /***********************************************************************
924 * LoadKeyboardLayout32W (USER32.368)
926 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
928 FIXME(keyboard, "%p, %d): stub\n", pwszKLID, Flags);
929 return 0;