Changed 'GetDisplayMode' to return the mode previously set by
[wine/hacks.git] / windows / input.c
blob17233d7b18db02c4b0bb302fbd38b5155aa4c688
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 "heap.h"
23 #include "input.h"
24 #include "keyboard.h"
25 #include "mouse.h"
26 #include "message.h"
27 #include "sysmetrics.h"
28 #include "debug.h"
29 #include "debugtools.h"
30 #include "struct32.h"
31 #include "winerror.h"
32 #include "task.h"
34 static BOOL InputEnabled = TRUE;
35 static BOOL SwappedButtons = FALSE;
37 BOOL MouseButtonsStates[3];
38 BOOL AsyncMouseButtonsStates[3];
39 BYTE InputKeyStateTable[256];
40 BYTE QueueKeyStateTable[256];
41 BYTE AsyncKeyStateTable[256];
43 typedef union
45 struct
47 unsigned long count : 16;
48 unsigned long code : 8;
49 unsigned long extended : 1;
50 unsigned long unused : 2;
51 unsigned long win_internal : 2;
52 unsigned long context : 1;
53 unsigned long previous : 1;
54 unsigned long transition : 1;
55 } lp1;
56 unsigned long lp2;
57 } KEYLP;
59 /***********************************************************************
60 * keybd_event (USER32.583)
62 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
63 DWORD dwFlags, DWORD dwExtraInfo )
65 DWORD posX, posY, time, extra;
66 WORD message;
67 KEYLP keylp;
68 keylp.lp2 = 0;
70 if (!InputEnabled) return;
73 * If we are called by the Wine keyboard driver, use the additional
74 * info pointed to by the dwExtraInfo argument.
75 * Otherwise, we need to determine that info ourselves (probably
76 * less accurate, but we can't help that ...).
78 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_KEYBDEVENT) )
79 && ((WINE_KEYBDEVENT *)dwExtraInfo)->magic == WINE_KEYBDEVENT_MAGIC )
81 WINE_KEYBDEVENT *wke = (WINE_KEYBDEVENT *)dwExtraInfo;
82 posX = wke->posX;
83 posY = wke->posY;
84 time = wke->time;
85 extra = 0;
87 else
89 DWORD keyState;
90 time = GetTickCount();
91 extra = dwExtraInfo;
93 if ( !EVENT_QueryPointer( &posX, &posY, &keyState ))
94 return;
98 keylp.lp1.count = 1;
99 keylp.lp1.code = bScan;
100 keylp.lp1.extended = (dwFlags & KEYEVENTF_EXTENDEDKEY) != 0;
101 keylp.lp1.win_internal = 0; /* this has something to do with dialogs,
102 * don't remember where I read it - AK */
103 /* it's '1' under windows, when a dialog box appears
104 * and you press one of the underlined keys - DF*/
106 if ( dwFlags & KEYEVENTF_KEYUP )
108 BOOL sysKey = (InputKeyStateTable[VK_MENU] & 0x80)
109 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
110 && !(dwFlags & KEYEVENTF_WINE_FORCEEXTENDED); /* for Alt from AltGr */
112 InputKeyStateTable[bVk] &= ~0x80;
113 keylp.lp1.previous = 1;
114 keylp.lp1.transition = 1;
115 message = sysKey ? WM_SYSKEYUP : WM_KEYUP;
117 else
119 keylp.lp1.previous = (InputKeyStateTable[bVk] & 0x80) != 0;
120 keylp.lp1.transition = 0;
122 if (!(InputKeyStateTable[bVk] & 0x80))
123 InputKeyStateTable[bVk] ^= 0x01;
124 InputKeyStateTable[bVk] |= 0x80;
126 message = (InputKeyStateTable[VK_MENU] & 0x80)
127 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
128 ? WM_SYSKEYDOWN : WM_KEYDOWN;
131 if ( message == WM_SYSKEYDOWN || message == WM_SYSKEYUP )
132 keylp.lp1.context = (InputKeyStateTable[VK_MENU] & 0x80) != 0; /* 1 if alt */
135 TRACE(key, " wParam=%04X, lParam=%08lX\n", bVk, keylp.lp2 );
136 TRACE(key, " InputKeyState=%X\n", InputKeyStateTable[bVk] );
138 hardware_event( message, bVk, keylp.lp2, posX, posY, time, extra );
141 /***********************************************************************
142 * mouse_event (USER32.584)
144 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
145 DWORD cButtons, DWORD dwExtraInfo )
147 DWORD posX, posY, keyState, time, extra;
149 if (!InputEnabled) return;
152 * If we are called by the Wine mouse driver, use the additional
153 * info pointed to by the dwExtraInfo argument.
154 * Otherwise, we need to determine that info ourselves (probably
155 * less accurate, but we can't help that ...).
157 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_MOUSEEVENT) )
158 && ((WINE_MOUSEEVENT *)dwExtraInfo)->magic == WINE_MOUSEEVENT_MAGIC )
160 WINE_MOUSEEVENT *wme = (WINE_MOUSEEVENT *)dwExtraInfo;
161 keyState = wme->keyState;
162 time = wme->time;
163 extra = (DWORD)wme->hWnd;
165 assert( dwFlags & MOUSEEVENTF_ABSOLUTE );
166 posX = (dx * SYSMETRICS_CXSCREEN) >> 16;
167 posY = (dy * SYSMETRICS_CYSCREEN) >> 16;
169 else
171 time = GetTickCount();
172 extra = dwExtraInfo;
174 if ( !EVENT_QueryPointer( &posX, &posY, &keyState ))
175 return;
177 if ( dwFlags & MOUSEEVENTF_MOVE )
179 if ( dwFlags & MOUSEEVENTF_ABSOLUTE )
181 posX = (dx * SYSMETRICS_CXSCREEN) >> 16;
182 posY = (dy * SYSMETRICS_CYSCREEN) >> 16;
184 else
186 posX += dx;
187 posY += dy;
189 /* We have to actually move the cursor */
190 SetCursorPos( posX, posY );
194 if ( dwFlags & MOUSEEVENTF_MOVE )
196 hardware_event( WM_MOUSEMOVE,
197 keyState, 0L, posX, posY, time, extra );
199 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN) )
201 MouseButtonsStates[0] = AsyncMouseButtonsStates[0] = TRUE;
202 hardware_event( WM_LBUTTONDOWN,
203 keyState, 0L, posX, posY, time, extra );
205 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP) )
207 MouseButtonsStates[0] = FALSE;
208 hardware_event( WM_LBUTTONUP,
209 keyState, 0L, posX, posY, time, extra );
211 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN) )
213 MouseButtonsStates[2] = AsyncMouseButtonsStates[2] = TRUE;
214 hardware_event( WM_RBUTTONDOWN,
215 keyState, 0L, posX, posY, time, extra );
217 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_LEFTUP) )
219 MouseButtonsStates[2] = FALSE;
220 hardware_event( WM_RBUTTONUP,
221 keyState, 0L, posX, posY, time, extra );
223 if ( dwFlags & MOUSEEVENTF_MIDDLEDOWN )
225 MouseButtonsStates[1] = AsyncMouseButtonsStates[1] = TRUE;
226 hardware_event( WM_MBUTTONDOWN,
227 keyState, 0L, posX, posY, time, extra );
229 if ( dwFlags & MOUSEEVENTF_MIDDLEUP )
231 MouseButtonsStates[1] = FALSE;
232 hardware_event( WM_MBUTTONUP,
233 keyState, 0L, posX, posY, time, extra );
237 /**********************************************************************
238 * EnableHardwareInput (USER.331)
240 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
242 BOOL16 bOldState = InputEnabled;
243 FIXME(event,"(%d) - stub\n", bEnable);
244 InputEnabled = bEnable;
245 return bOldState;
249 /***********************************************************************
250 * SwapMouseButton16 (USER.186)
252 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
254 BOOL16 ret = SwappedButtons;
255 SwappedButtons = fSwap;
256 return ret;
260 /***********************************************************************
261 * SwapMouseButton32 (USER32.537)
263 BOOL WINAPI SwapMouseButton( BOOL fSwap )
265 BOOL ret = SwappedButtons;
266 SwappedButtons = fSwap;
267 return ret;
270 /**********************************************************************
271 * EVENT_Capture
273 * We need this to be able to generate double click messages
274 * when menu code captures mouse in the window without CS_DBLCLK style.
276 HWND EVENT_Capture(HWND hwnd, INT16 ht)
278 HWND capturePrev = 0, captureWnd = 0;
279 MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0;
280 WND* wndPtr = 0;
281 INT16 captureHT = 0;
283 /* Get the messageQ for the current thread */
284 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
286 WARN( win, "\tCurrent message queue not found. Exiting!\n" );
287 goto CLEANUP;
290 /* Get the current capture window from the perQ data of the current message Q */
291 capturePrev = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
293 if (!hwnd)
295 captureWnd = 0L;
296 captureHT = 0;
298 else
300 wndPtr = WIN_FindWndPtr( hwnd );
301 if (wndPtr)
303 TRACE(win, "(0x%04x)\n", hwnd );
304 captureWnd = hwnd;
305 captureHT = ht;
309 /* Update the perQ capture window and send messages */
310 if( capturePrev != captureWnd )
312 if (wndPtr)
314 /* Retrieve the message queue associated with this window */
315 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
316 if ( !pMsgQ )
318 WARN( win, "\tMessage queue not found. Exiting!\n" );
319 goto CLEANUP;
322 /* Make sure that message queue for the window we are setting capture to
323 * shares the same perQ data as the current threads message queue.
325 if ( pCurMsgQ->pQData != pMsgQ->pQData )
326 goto CLEANUP;
329 PERQDATA_SetCaptureWnd( pCurMsgQ->pQData, captureWnd );
330 PERQDATA_SetCaptureInfo( pCurMsgQ->pQData, captureHT );
332 if( capturePrev )
334 WND* wndPtr = WIN_FindWndPtr( capturePrev );
335 if( wndPtr && (wndPtr->flags & WIN_ISWIN32) )
336 SendMessageA( capturePrev, WM_CAPTURECHANGED, 0L, hwnd);
337 WIN_ReleaseWndPtr(wndPtr);
341 CLEANUP:
342 /* Unlock the queues before returning */
343 if ( pMsgQ )
344 QUEUE_Unlock( pMsgQ );
345 if ( pCurMsgQ )
346 QUEUE_Unlock( pCurMsgQ );
348 WIN_ReleaseWndPtr(wndPtr);
349 return capturePrev;
353 /**********************************************************************
354 * SetCapture16 (USER.18)
356 HWND16 WINAPI SetCapture16( HWND16 hwnd )
358 return (HWND16)EVENT_Capture( hwnd, HTCLIENT );
362 /**********************************************************************
363 * SetCapture32 (USER32.464)
365 HWND WINAPI SetCapture( HWND hwnd )
367 return EVENT_Capture( hwnd, HTCLIENT );
371 /**********************************************************************
372 * ReleaseCapture (USER.19) (USER32.439)
374 BOOL WINAPI ReleaseCapture(void)
376 return (EVENT_Capture( 0, 0 ) != 0);
380 /**********************************************************************
381 * GetCapture16 (USER.236)
383 HWND16 WINAPI GetCapture16(void)
385 return (HWND16)GetCapture();
388 /**********************************************************************
389 * GetCapture32 (USER32.208)
391 HWND WINAPI GetCapture(void)
393 MESSAGEQUEUE *pCurMsgQ = 0;
394 HWND hwndCapture = 0;
396 /* Get the messageQ for the current thread */
397 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
399 TRACE( win, "GetCapture32: Current message queue not found. Exiting!\n" );
400 return 0;
403 /* Get the current capture window from the perQ data of the current message Q */
404 hwndCapture = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
406 QUEUE_Unlock( pCurMsgQ );
407 return hwndCapture;
410 /**********************************************************************
411 * GetKeyState (USER.106)
413 INT16 WINAPI GetKeyState16(INT16 vkey)
415 return GetKeyState(vkey);
418 /**********************************************************************
419 * GetKeyState (USER32.249)
421 * An application calls the GetKeyState function in response to a
422 * keyboard-input message. This function retrieves the state of the key
423 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
425 INT16 WINAPI GetKeyState(INT vkey)
427 INT retval;
429 switch (vkey)
431 case VK_LBUTTON : /* VK_LBUTTON is 1 */
432 retval = MouseButtonsStates[0] ? 0x8000 : 0;
433 break;
434 case VK_MBUTTON : /* VK_MBUTTON is 4 */
435 retval = MouseButtonsStates[1] ? 0x8000 : 0;
436 break;
437 case VK_RBUTTON : /* VK_RBUTTON is 2 */
438 retval = MouseButtonsStates[2] ? 0x8000 : 0;
439 break;
440 default :
441 if (vkey >= 'a' && vkey <= 'z')
442 vkey += 'A' - 'a';
443 retval = ( (WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
444 (WORD)(QueueKeyStateTable[vkey] & 0x01);
446 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
447 return retval;
450 /**********************************************************************
451 * GetKeyboardState (USER.222)(USER32.254)
453 * An application calls the GetKeyboardState function in response to a
454 * keyboard-input message. This function retrieves the state of the keyboard
455 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
457 VOID WINAPI GetKeyboardState(LPBYTE lpKeyState)
459 TRACE(key, "(%p)\n", lpKeyState);
460 if (lpKeyState != NULL) {
461 QueueKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
462 QueueKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
463 QueueKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
464 memcpy(lpKeyState, QueueKeyStateTable, 256);
468 /**********************************************************************
469 * SetKeyboardState (USER.223)(USER32.484)
471 VOID WINAPI SetKeyboardState(LPBYTE lpKeyState)
473 TRACE(key, "(%p)\n", lpKeyState);
474 if (lpKeyState != NULL) {
475 memcpy(QueueKeyStateTable, lpKeyState, 256);
476 MouseButtonsStates[0] = (QueueKeyStateTable[VK_LBUTTON] != 0);
477 MouseButtonsStates[1] = (QueueKeyStateTable[VK_MBUTTON] != 0);
478 MouseButtonsStates[2] = (QueueKeyStateTable[VK_RBUTTON] != 0);
482 /**********************************************************************
483 * GetAsyncKeyState32 (USER32.207)
485 * Determine if a key is or was pressed. retval has high-order
486 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
487 * been pressed.
489 * This uses the variable AsyncMouseButtonsStates and
490 * AsyncKeyStateTable (set in event.c) which have the mouse button
491 * number or key number (whichever is applicable) set to true if the
492 * mouse or key had been depressed since the last call to
493 * GetAsyncKeyState.
495 WORD WINAPI GetAsyncKeyState(INT nKey)
497 short retval;
499 switch (nKey) {
500 case VK_LBUTTON:
501 retval = (AsyncMouseButtonsStates[0] ? 0x0001 : 0) |
502 (MouseButtonsStates[0] ? 0x8000 : 0);
503 break;
504 case VK_MBUTTON:
505 retval = (AsyncMouseButtonsStates[1] ? 0x0001 : 0) |
506 (MouseButtonsStates[1] ? 0x8000 : 0);
507 break;
508 case VK_RBUTTON:
509 retval = (AsyncMouseButtonsStates[2] ? 0x0001 : 0) |
510 (MouseButtonsStates[2] ? 0x8000 : 0);
511 break;
512 default:
513 retval = AsyncKeyStateTable[nKey] |
514 ((InputKeyStateTable[nKey] & 0x80) ? 0x8000 : 0);
515 break;
518 /* all states to false */
519 memset( AsyncMouseButtonsStates, 0, sizeof(AsyncMouseButtonsStates) );
520 memset( AsyncKeyStateTable, 0, sizeof(AsyncKeyStateTable) );
522 TRACE(key, "(%x) -> %x\n", nKey, retval);
523 return retval;
526 /**********************************************************************
527 * GetAsyncKeyState16 (USER.249)
529 WORD WINAPI GetAsyncKeyState16(INT16 nKey)
531 return GetAsyncKeyState(nKey);
534 /**********************************************************************
535 * KBD_translate_accelerator
537 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
539 static BOOL KBD_translate_accelerator(HWND hWnd,LPMSG msg,
540 BYTE fVirt,WORD key,WORD cmd)
542 BOOL sendmsg = FALSE;
544 if(msg->wParam == key)
546 if (msg->message == WM_CHAR) {
547 if ( !(fVirt & FALT) && !(fVirt & FVIRTKEY) )
549 TRACE(accel,"found accel for WM_CHAR: ('%c')\n",
550 msg->wParam&0xff);
551 sendmsg=TRUE;
553 } else {
554 if(fVirt & FVIRTKEY) {
555 INT mask = 0;
556 TRACE(accel,"found accel for virt_key %04x (scan %04x)\n",
557 msg->wParam,0xff & HIWORD(msg->lParam));
558 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
559 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
560 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
561 if(mask == (fVirt & (FSHIFT | FCONTROL | FALT)))
562 sendmsg=TRUE;
563 else
564 TRACE(accel,", but incorrect SHIFT/CTRL/ALT-state\n");
566 else
568 if (!(msg->lParam & 0x01000000)) /* no special_key */
570 if ((fVirt & FALT) && (msg->lParam & 0x20000000))
571 { /* ^^ ALT pressed */
572 TRACE(accel,"found accel for Alt-%c\n", msg->wParam&0xff);
573 sendmsg=TRUE;
579 if (sendmsg) /* found an accelerator, but send a message... ? */
581 INT16 iSysStat,iStat,mesg=0;
582 HMENU16 hMenu;
584 if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
585 mesg=1;
586 else
587 if (GetCapture())
588 mesg=2;
589 else
590 if (!IsWindowEnabled(hWnd))
591 mesg=3;
592 else
594 WND* wndPtr = WIN_FindWndPtr(hWnd);
596 hMenu = (wndPtr->dwStyle & WS_CHILD) ? 0 : (HMENU)wndPtr->wIDmenu;
597 iSysStat = (wndPtr->hSysMenu) ? GetMenuState(GetSubMenu16(wndPtr->hSysMenu, 0),
598 cmd, MF_BYCOMMAND) : -1 ;
599 iStat = (hMenu) ? GetMenuState(hMenu,
600 cmd, MF_BYCOMMAND) : -1 ;
602 WIN_ReleaseWndPtr(wndPtr);
604 if (iSysStat!=-1)
606 if (iSysStat & (MF_DISABLED|MF_GRAYED))
607 mesg=4;
608 else
609 mesg=WM_SYSCOMMAND;
611 else
613 if (iStat!=-1)
615 if (IsIconic(hWnd))
616 mesg=5;
617 else
619 if (iStat & (MF_DISABLED|MF_GRAYED))
620 mesg=6;
621 else
622 mesg=WM_COMMAND;
625 else
626 mesg=WM_COMMAND;
629 if ( mesg==WM_COMMAND || mesg==WM_SYSCOMMAND )
631 TRACE(accel,", sending %s, wParam=%0x\n",
632 mesg==WM_COMMAND ? "WM_COMMAND" : "WM_SYSCOMMAND",
633 cmd);
634 SendMessageA(hWnd, mesg, cmd, 0x00010000L);
636 else
638 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
639 * #0: unknown (please report!)
640 * #1: for WM_KEYUP,WM_SYSKEYUP
641 * #2: mouse is captured
642 * #3: window is disabled
643 * #4: it's a disabled system menu option
644 * #5: it's a menu option, but window is iconic
645 * #6: it's a menu option, but disabled
647 TRACE(accel,", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg);
648 if(mesg==0)
649 ERR(accel, " unknown reason - please report!");
651 return TRUE;
654 return FALSE;
657 /**********************************************************************
658 * TranslateAccelerator32 (USER32.551)(USER32.552)(USER32.553)
660 INT WINAPI TranslateAccelerator(HWND hWnd, HACCEL hAccel, LPMSG msg)
662 /* YES, Accel16! */
663 LPACCEL16 lpAccelTbl = (LPACCEL16)LockResource16(hAccel);
664 int i;
666 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);
668 if (hAccel == 0 || msg == NULL ||
669 (msg->message != WM_KEYDOWN &&
670 msg->message != WM_KEYUP &&
671 msg->message != WM_SYSKEYDOWN &&
672 msg->message != WM_SYSKEYUP &&
673 msg->message != WM_CHAR)) {
674 WARN(accel, "erraneous input parameters\n");
675 SetLastError(ERROR_INVALID_PARAMETER);
676 return 0;
679 TRACE(accel, "TranslateAccelerators hAccel=%04x, hWnd=%04x,"
680 "msg->hwnd=%04x, msg->message=%04x\n",
681 hAccel,hWnd,msg->hwnd,msg->message);
683 i = 0;
686 if (KBD_translate_accelerator(hWnd,msg,lpAccelTbl[i].fVirt,
687 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
688 return 1;
689 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
690 WARN(accel, "couldn't translate accelerator key\n");
691 return 0;
694 /**********************************************************************
695 * TranslateAccelerator16 (USER.178)
697 INT16 WINAPI TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
699 LPACCEL16 lpAccelTbl = (LPACCEL16)LockResource16(hAccel);
700 int i;
701 MSG msg32;
703 if (hAccel == 0 || msg == NULL ||
704 (msg->message != WM_KEYDOWN &&
705 msg->message != WM_KEYUP &&
706 msg->message != WM_SYSKEYDOWN &&
707 msg->message != WM_SYSKEYUP &&
708 msg->message != WM_CHAR)) {
709 WARN(accel, "erraneous input parameters\n");
710 SetLastError(ERROR_INVALID_PARAMETER);
711 return 0;
714 TRACE(accel, "TranslateAccelerators hAccel=%04x, hWnd=%04x,\
715 msg->hwnd=%04x, msg->message=%04x\n", hAccel,hWnd,msg->hwnd,msg->message);
716 STRUCT32_MSG16to32(msg,&msg32);
719 i = 0;
722 if (KBD_translate_accelerator(hWnd,&msg32,lpAccelTbl[i].fVirt,
723 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
724 return 1;
725 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
726 WARN(accel, "couldn't translate accelerator key\n");
727 return 0;
731 /**********************************************************************
732 * VkKeyScanA (USER32.573)
734 WORD WINAPI VkKeyScanA(CHAR cChar)
736 return VkKeyScan16(cChar);
739 /******************************************************************************
740 * VkKeyScanW (USER32.576)
742 WORD WINAPI VkKeyScanW(WCHAR cChar)
744 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
747 /**********************************************************************
748 * VkKeyScanExA (USER32.574)
750 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
752 /* FIXME: complete workaround this is */
753 return VkKeyScan16(cChar);
756 /******************************************************************************
757 * VkKeyScanExW (USER32.575)
759 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
761 /* FIXME: complete workaround this is */
762 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
765 /******************************************************************************
766 * GetKeyboardType32 (USER32.255)
768 INT WINAPI GetKeyboardType(INT nTypeFlag)
770 return GetKeyboardType16(nTypeFlag);
773 /******************************************************************************
774 * MapVirtualKey32A (USER32.383)
776 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
778 return MapVirtualKey16(code,maptype);
781 /******************************************************************************
782 * MapVirtualKey32W (USER32.385)
784 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
786 return MapVirtualKey16(code,maptype);
789 /******************************************************************************
790 * MapVirtualKeyEx32A (USER32.384)
792 UINT WINAPI MapVirtualKeyEx32A(UINT code, UINT maptype, HKL hkl)
794 if (hkl)
795 FIXME(keyboard,"(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
796 return MapVirtualKey16(code,maptype);
799 /****************************************************************************
800 * GetKBCodePage32 (USER32.246)
802 UINT WINAPI GetKBCodePage(void)
804 return GetKBCodePage16();
807 /****************************************************************************
808 * GetKeyboardLayoutName16 (USER.477)
810 INT16 WINAPI GetKeyboardLayoutName16(LPSTR pwszKLID)
812 return GetKeyboardLayoutNameA(pwszKLID);
815 /***********************************************************************
816 * GetKeyboardLayout (USER32.250)
818 * FIXME: - device handle for keyboard layout defaulted to
819 * the language id. This is the way Windows default works.
820 * - the thread identifier (dwLayout) is also ignored.
822 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
824 HKL layout;
825 layout = GetSystemDefaultLCID(); /* FIXME */
826 layout |= (layout<<16); /* FIXME */
827 TRACE(keyboard,"returning %08x\n",layout);
828 return layout;
831 /****************************************************************************
832 * GetKeyboardLayoutName32A (USER32.252)
834 INT WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID)
836 sprintf(pwszKLID, "%08x",GetKeyboardLayout(0));
837 return 1;
840 /****************************************************************************
841 * GetKeyboardLayoutName32W (USER32.253)
843 INT WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
845 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
846 int res = GetKeyboardLayoutNameA(buf);
847 lstrcpyAtoW(pwszKLID,buf);
848 HeapFree( GetProcessHeap(), 0, buf );
849 return res;
852 /****************************************************************************
853 * GetKeyNameText32A (USER32.247)
855 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
857 return GetKeyNameText16(lParam,lpBuffer,nSize);
860 /****************************************************************************
861 * GetKeyNameText32W (USER32.248)
863 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
865 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, nSize );
866 int res = GetKeyNameTextA(lParam,buf,nSize);
868 lstrcpynAtoW(lpBuffer,buf,nSize);
869 HeapFree( GetProcessHeap(), 0, buf );
870 return res;
873 /****************************************************************************
874 * ToAscii32 (USER32.546)
876 INT WINAPI ToAscii( UINT virtKey,UINT scanCode,LPBYTE lpKeyState,
877 LPWORD lpChar,UINT flags )
879 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
882 /****************************************************************************
883 * ToAscii32 (USER32.547)
885 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
886 LPWORD lpChar, UINT flags, HKL dwhkl )
888 /* FIXME: need true implementation */
889 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
892 /**********************************************************************
893 * ActivateKeyboardLayout32 (USER32.1)
895 * Call ignored. WINE supports only system default keyboard layout.
897 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
899 TRACE(keyboard, "(%d, %d)\n", hLayout, flags);
900 ERR(keyboard,"Only default system keyboard layout supported. Call ignored.\n");
901 return 0;
905 /***********************************************************************
906 * GetKeyboardLayoutList (USER32.251)
908 * FIXME: Supports only the system default language and layout and
909 * returns only 1 value.
911 * Return number of values available if either input parm is
912 * 0, per MS documentation.
915 INT WINAPI GetKeyboardLayoutList(INT nBuff,HKL *layouts)
917 TRACE(keyboard,"(%d,%p)\n",nBuff,layouts);
918 if (!nBuff || !layouts)
919 return 1;
920 if (layouts)
921 layouts[0] = GetKeyboardLayout(0);
922 return 1;
926 /***********************************************************************
927 * RegisterHotKey (USER32.433)
929 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk) {
930 FIXME(keyboard,"(0x%08x,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
931 return TRUE;
934 /***********************************************************************
935 * UnregisterHotKey (USER32.565)
937 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id) {
938 FIXME(keyboard,"(0x%08x,%d): stub\n",hwnd,id);
939 return TRUE;
943 /***********************************************************************
944 * ToUnicode32 (USER32.548)
946 INT WINAPI ToUnicode(
947 UINT wVirtKey,
948 UINT wScanCode,
949 PBYTE lpKeyState,
950 LPWSTR pwszBuff,
951 int cchBuff,
952 UINT wFlags) {
954 FIXME(keyboard,": stub\n");
955 return 0;
958 /***********************************************************************
959 * LoadKeyboardLayout32A (USER32.367)
960 * Call ignored. WINE supports only system default keyboard layout.
962 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
964 TRACE(keyboard, "(%s, %d)\n", pwszKLID, Flags);
965 ERR(keyboard,"Only default system keyboard layout supported. Call ignored.\n");
966 return 0;
969 /***********************************************************************
970 * LoadKeyboardLayout32W (USER32.368)
972 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
974 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
975 int res;
976 lstrcpynWtoA(buf,pwszKLID,8);
977 buf[8] = 0;
978 res = LoadKeyboardLayoutA(buf, Flags);
979 HeapFree( GetProcessHeap(), 0, buf );
980 return res;