Handle suspend/resume_thread requests in phase STARTING correctly.
[wine/hacks.git] / windows / input.c
blob7d85979b10ed66a61a6b571e82f5dfde62cf318f
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);
338 WIN_ReleaseWndPtr(wndPtr);
342 CLEANUP:
343 /* Unlock the queues before returning */
344 if ( pMsgQ )
345 QUEUE_Unlock( pMsgQ );
346 if ( pCurMsgQ )
347 QUEUE_Unlock( pCurMsgQ );
349 WIN_ReleaseWndPtr(wndPtr);
350 return capturePrev;
354 /**********************************************************************
355 * SetCapture16 (USER.18)
357 HWND16 WINAPI SetCapture16( HWND16 hwnd )
359 return (HWND16)EVENT_Capture( hwnd, HTCLIENT );
363 /**********************************************************************
364 * SetCapture32 (USER32.464)
366 HWND WINAPI SetCapture( HWND hwnd )
368 return EVENT_Capture( hwnd, HTCLIENT );
372 /**********************************************************************
373 * ReleaseCapture (USER.19) (USER32.439)
375 void WINAPI ReleaseCapture(void)
377 EVENT_Capture( 0, 0 );
381 /**********************************************************************
382 * GetCapture16 (USER.236)
384 HWND16 WINAPI GetCapture16(void)
386 return (HWND16)GetCapture();
389 /**********************************************************************
390 * GetCapture32 (USER32.208)
392 HWND WINAPI GetCapture(void)
394 MESSAGEQUEUE *pCurMsgQ = 0;
395 HWND hwndCapture = 0;
397 /* Get the messageQ for the current thread */
398 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
400 TRACE( win, "GetCapture32: Current message queue not found. Exiting!\n" );
401 return 0;
404 /* Get the current capture window from the perQ data of the current message Q */
405 hwndCapture = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
407 QUEUE_Unlock( pCurMsgQ );
408 return hwndCapture;
411 /**********************************************************************
412 * GetKeyState (USER.106)
414 INT16 WINAPI GetKeyState16(INT16 vkey)
416 return GetKeyState(vkey);
419 /**********************************************************************
420 * GetKeyState (USER32.249)
422 * An application calls the GetKeyState function in response to a
423 * keyboard-input message. This function retrieves the state of the key
424 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
426 INT16 WINAPI GetKeyState(INT vkey)
428 INT retval;
430 switch (vkey)
432 case VK_LBUTTON : /* VK_LBUTTON is 1 */
433 retval = MouseButtonsStates[0] ? 0x8000 : 0;
434 break;
435 case VK_MBUTTON : /* VK_MBUTTON is 4 */
436 retval = MouseButtonsStates[1] ? 0x8000 : 0;
437 break;
438 case VK_RBUTTON : /* VK_RBUTTON is 2 */
439 retval = MouseButtonsStates[2] ? 0x8000 : 0;
440 break;
441 default :
442 if (vkey >= 'a' && vkey <= 'z')
443 vkey += 'A' - 'a';
444 retval = ( (WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
445 (WORD)(QueueKeyStateTable[vkey] & 0x01);
447 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
448 return retval;
451 /**********************************************************************
452 * GetKeyboardState (USER.222)(USER32.254)
454 * An application calls the GetKeyboardState function in response to a
455 * keyboard-input message. This function retrieves the state of the keyboard
456 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
458 VOID WINAPI GetKeyboardState(LPBYTE lpKeyState)
460 TRACE(key, "(%p)\n", lpKeyState);
461 if (lpKeyState != NULL) {
462 QueueKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
463 QueueKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
464 QueueKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
465 memcpy(lpKeyState, QueueKeyStateTable, 256);
469 /**********************************************************************
470 * SetKeyboardState (USER.223)(USER32.484)
472 VOID WINAPI SetKeyboardState(LPBYTE lpKeyState)
474 TRACE(key, "(%p)\n", lpKeyState);
475 if (lpKeyState != NULL) {
476 memcpy(QueueKeyStateTable, lpKeyState, 256);
477 MouseButtonsStates[0] = (QueueKeyStateTable[VK_LBUTTON] != 0);
478 MouseButtonsStates[1] = (QueueKeyStateTable[VK_MBUTTON] != 0);
479 MouseButtonsStates[2] = (QueueKeyStateTable[VK_RBUTTON] != 0);
483 /**********************************************************************
484 * GetAsyncKeyState32 (USER32.207)
486 * Determine if a key is or was pressed. retval has high-order
487 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
488 * been pressed.
490 * This uses the variable AsyncMouseButtonsStates and
491 * AsyncKeyStateTable (set in event.c) which have the mouse button
492 * number or key number (whichever is applicable) set to true if the
493 * mouse or key had been depressed since the last call to
494 * GetAsyncKeyState.
496 WORD WINAPI GetAsyncKeyState(INT nKey)
498 short retval;
500 switch (nKey) {
501 case VK_LBUTTON:
502 retval = (AsyncMouseButtonsStates[0] ? 0x0001 : 0) |
503 (MouseButtonsStates[0] ? 0x8000 : 0);
504 break;
505 case VK_MBUTTON:
506 retval = (AsyncMouseButtonsStates[1] ? 0x0001 : 0) |
507 (MouseButtonsStates[1] ? 0x8000 : 0);
508 break;
509 case VK_RBUTTON:
510 retval = (AsyncMouseButtonsStates[2] ? 0x0001 : 0) |
511 (MouseButtonsStates[2] ? 0x8000 : 0);
512 break;
513 default:
514 retval = AsyncKeyStateTable[nKey] |
515 ((InputKeyStateTable[nKey] & 0x80) ? 0x8000 : 0);
516 break;
519 /* all states to false */
520 memset( AsyncMouseButtonsStates, 0, sizeof(AsyncMouseButtonsStates) );
521 memset( AsyncKeyStateTable, 0, sizeof(AsyncKeyStateTable) );
523 TRACE(key, "(%x) -> %x\n", nKey, retval);
524 return retval;
527 /**********************************************************************
528 * GetAsyncKeyState16 (USER.249)
530 WORD WINAPI GetAsyncKeyState16(INT16 nKey)
532 return GetAsyncKeyState(nKey);
535 /**********************************************************************
536 * KBD_translate_accelerator
538 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
540 static BOOL KBD_translate_accelerator(HWND hWnd,LPMSG msg,
541 BYTE fVirt,WORD key,WORD cmd)
543 BOOL sendmsg = FALSE;
545 if(msg->wParam == key)
547 if (msg->message == WM_CHAR) {
548 if ( !(fVirt & FALT) && !(fVirt & FVIRTKEY) )
550 TRACE(accel,"found accel for WM_CHAR: ('%c')\n",
551 msg->wParam&0xff);
552 sendmsg=TRUE;
554 } else {
555 if(fVirt & FVIRTKEY) {
556 INT mask = 0;
557 TRACE(accel,"found accel for virt_key %04x (scan %04x)\n",
558 msg->wParam,0xff & HIWORD(msg->lParam));
559 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
560 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
561 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
562 if(mask == (fVirt & (FSHIFT | FCONTROL | FALT)))
563 sendmsg=TRUE;
564 else
565 TRACE(accel,", but incorrect SHIFT/CTRL/ALT-state\n");
567 else
569 if (!(msg->lParam & 0x01000000)) /* no special_key */
571 if ((fVirt & FALT) && (msg->lParam & 0x20000000))
572 { /* ^^ ALT pressed */
573 TRACE(accel,"found accel for Alt-%c\n", msg->wParam&0xff);
574 sendmsg=TRUE;
580 if (sendmsg) /* found an accelerator, but send a message... ? */
582 INT16 iSysStat,iStat,mesg=0;
583 HMENU16 hMenu;
585 if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
586 mesg=1;
587 else
588 if (GetCapture())
589 mesg=2;
590 else
591 if (!IsWindowEnabled(hWnd))
592 mesg=3;
593 else
595 WND* wndPtr = WIN_FindWndPtr(hWnd);
597 hMenu = (wndPtr->dwStyle & WS_CHILD) ? 0 : (HMENU)wndPtr->wIDmenu;
598 iSysStat = (wndPtr->hSysMenu) ? GetMenuState(GetSubMenu16(wndPtr->hSysMenu, 0),
599 cmd, MF_BYCOMMAND) : -1 ;
600 iStat = (hMenu) ? GetMenuState(hMenu,
601 cmd, MF_BYCOMMAND) : -1 ;
603 WIN_ReleaseWndPtr(wndPtr);
605 if (iSysStat!=-1)
607 if (iSysStat & (MF_DISABLED|MF_GRAYED))
608 mesg=4;
609 else
610 mesg=WM_SYSCOMMAND;
612 else
614 if (iStat!=-1)
616 if (IsIconic(hWnd))
617 mesg=5;
618 else
620 if (iStat & (MF_DISABLED|MF_GRAYED))
621 mesg=6;
622 else
623 mesg=WM_COMMAND;
626 else
627 mesg=WM_COMMAND;
630 if ( mesg==WM_COMMAND || mesg==WM_SYSCOMMAND )
632 TRACE(accel,", sending %s, wParam=%0x\n",
633 mesg==WM_COMMAND ? "WM_COMMAND" : "WM_SYSCOMMAND",
634 cmd);
635 SendMessageA(hWnd, mesg, cmd, 0x00010000L);
637 else
639 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
640 * #0: unknown (please report!)
641 * #1: for WM_KEYUP,WM_SYSKEYUP
642 * #2: mouse is captured
643 * #3: window is disabled
644 * #4: it's a disabled system menu option
645 * #5: it's a menu option, but window is iconic
646 * #6: it's a menu option, but disabled
648 TRACE(accel,", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg);
649 if(mesg==0)
650 ERR(accel, " unknown reason - please report!");
652 return TRUE;
655 return FALSE;
658 /**********************************************************************
659 * TranslateAccelerator32 (USER32.551)(USER32.552)(USER32.553)
661 INT WINAPI TranslateAccelerator(HWND hWnd, HACCEL hAccel, LPMSG msg)
663 /* YES, Accel16! */
664 LPACCEL16 lpAccelTbl = (LPACCEL16)LockResource16(hAccel);
665 int i;
667 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);
669 if (hAccel == 0 || msg == NULL ||
670 (msg->message != WM_KEYDOWN &&
671 msg->message != WM_KEYUP &&
672 msg->message != WM_SYSKEYDOWN &&
673 msg->message != WM_SYSKEYUP &&
674 msg->message != WM_CHAR)) {
675 WARN(accel, "erraneous input parameters\n");
676 SetLastError(ERROR_INVALID_PARAMETER);
677 return 0;
680 TRACE(accel, "TranslateAccelerators hAccel=%04x, hWnd=%04x,"
681 "msg->hwnd=%04x, msg->message=%04x\n",
682 hAccel,hWnd,msg->hwnd,msg->message);
684 i = 0;
687 if (KBD_translate_accelerator(hWnd,msg,lpAccelTbl[i].fVirt,
688 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
689 return 1;
690 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
691 WARN(accel, "couldn't translate accelerator key\n");
692 return 0;
695 /**********************************************************************
696 * TranslateAccelerator16 (USER.178)
698 INT16 WINAPI TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
700 LPACCEL16 lpAccelTbl = (LPACCEL16)LockResource16(hAccel);
701 int i;
702 MSG msg32;
704 if (hAccel == 0 || msg == NULL ||
705 (msg->message != WM_KEYDOWN &&
706 msg->message != WM_KEYUP &&
707 msg->message != WM_SYSKEYDOWN &&
708 msg->message != WM_SYSKEYUP &&
709 msg->message != WM_CHAR)) {
710 WARN(accel, "erraneous input parameters\n");
711 SetLastError(ERROR_INVALID_PARAMETER);
712 return 0;
715 TRACE(accel, "TranslateAccelerators hAccel=%04x, hWnd=%04x,\
716 msg->hwnd=%04x, msg->message=%04x\n", hAccel,hWnd,msg->hwnd,msg->message);
717 STRUCT32_MSG16to32(msg,&msg32);
720 i = 0;
723 if (KBD_translate_accelerator(hWnd,&msg32,lpAccelTbl[i].fVirt,
724 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
725 return 1;
726 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
727 WARN(accel, "couldn't translate accelerator key\n");
728 return 0;
732 /**********************************************************************
733 * VkKeyScanA (USER32.573)
735 WORD WINAPI VkKeyScanA(CHAR cChar)
737 return VkKeyScan16(cChar);
740 /******************************************************************************
741 * VkKeyScanW (USER32.576)
743 WORD WINAPI VkKeyScanW(WCHAR cChar)
745 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
748 /******************************************************************************
749 * GetKeyboardType32 (USER32.255)
751 INT WINAPI GetKeyboardType(INT nTypeFlag)
753 return GetKeyboardType16(nTypeFlag);
756 /******************************************************************************
757 * MapVirtualKey32A (USER32.383)
759 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
761 return MapVirtualKey16(code,maptype);
764 /******************************************************************************
765 * MapVirtualKey32W (USER32.385)
767 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
769 return MapVirtualKey16(code,maptype);
772 /******************************************************************************
773 * MapVirtualKeyEx32A (USER32.384)
775 UINT WINAPI MapVirtualKeyEx32A(UINT code, UINT maptype, HKL hkl)
777 if (hkl)
778 FIXME(keyboard,"(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
779 return MapVirtualKey16(code,maptype);
782 /****************************************************************************
783 * GetKBCodePage32 (USER32.246)
785 UINT WINAPI GetKBCodePage(void)
787 return GetKBCodePage16();
790 /****************************************************************************
791 * GetKeyboardLayoutName16 (USER.477)
793 INT16 WINAPI GetKeyboardLayoutName16(LPSTR pwszKLID)
795 return GetKeyboardLayoutNameA(pwszKLID);
798 /***********************************************************************
799 * GetKeyboardLayout (USER32.250)
801 * FIXME: - device handle for keyboard layout defaulted to
802 * the language id. This is the way Windows default works.
803 * - the thread identifier (dwLayout) is also ignored.
805 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
807 HKL layout;
808 layout = GetSystemDefaultLCID(); /* FIXME */
809 layout |= (layout<<16); /* FIXME */
810 TRACE(keyboard,"returning %08x\n",layout);
811 return layout;
814 /****************************************************************************
815 * GetKeyboardLayoutName32A (USER32.252)
817 INT WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID)
819 sprintf(pwszKLID, "%08x",GetKeyboardLayout(0));
820 return 1;
823 /****************************************************************************
824 * GetKeyboardLayoutName32W (USER32.253)
826 INT WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
828 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
829 int res = GetKeyboardLayoutNameA(buf);
830 lstrcpyAtoW(pwszKLID,buf);
831 HeapFree( GetProcessHeap(), 0, buf );
832 return res;
835 /****************************************************************************
836 * GetKeyNameText32A (USER32.247)
838 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
840 return GetKeyNameText16(lParam,lpBuffer,nSize);
843 /****************************************************************************
844 * GetKeyNameText32W (USER32.248)
846 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
848 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, nSize );
849 int res = GetKeyNameTextA(lParam,buf,nSize);
851 lstrcpynAtoW(lpBuffer,buf,nSize);
852 HeapFree( GetProcessHeap(), 0, buf );
853 return res;
856 /****************************************************************************
857 * ToAscii32 (USER32.546)
859 INT WINAPI ToAscii( UINT virtKey,UINT scanCode,LPBYTE lpKeyState,
860 LPWORD lpChar,UINT flags )
862 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
865 /**********************************************************************
866 * ActivateKeyboardLayout32 (USER32.1)
868 * Call ignored. WINE supports only system default keyboard layout.
870 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
872 TRACE(keyboard, "(%d, %d)\n", hLayout, flags);
873 ERR(keyboard,"Only default system keyboard layout supported. Call ignored.\n");
874 return 0;
878 /***********************************************************************
879 * GetKeyboardLayoutList (USER32.251)
881 * FIXME: Supports only the system default language and layout and
882 * returns only 1 value.
884 * Return number of values available if either input parm is
885 * 0, per MS documentation.
888 INT WINAPI GetKeyboardLayoutList(INT nBuff,HKL *layouts)
890 TRACE(keyboard,"(%d,%p)\n",nBuff,layouts);
891 if (!nBuff || !layouts)
892 return 1;
893 if (layouts)
894 layouts[0] = GetKeyboardLayout(0);
895 return 1;
899 /***********************************************************************
900 * RegisterHotKey (USER32.433)
902 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk) {
903 FIXME(keyboard,"(0x%08x,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
904 return TRUE;
907 /***********************************************************************
908 * UnregisterHotKey (USER32.565)
910 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id) {
911 FIXME(keyboard,"(0x%08x,%d): stub\n",hwnd,id);
912 return TRUE;
916 /***********************************************************************
917 * ToUnicode32 (USER32.548)
919 INT WINAPI ToUnicode(
920 UINT wVirtKey,
921 UINT wScanCode,
922 PBYTE lpKeyState,
923 LPWSTR pwszBuff,
924 int cchBuff,
925 UINT wFlags) {
927 FIXME(keyboard,": stub\n");
928 return 0;
931 /***********************************************************************
932 * LoadKeyboardLayout32A (USER32.367)
933 * Call ignored. WINE supports only system default keyboard layout.
935 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
937 TRACE(keyboard, "(%s, %d)\n", pwszKLID, Flags);
938 ERR(keyboard,"Only default system keyboard layout supported. Call ignored.\n");
939 return 0;
942 /***********************************************************************
943 * LoadKeyboardLayout32W (USER32.368)
945 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
947 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
948 int res;
949 lstrcpynWtoA(buf,pwszKLID,8);
950 buf[8] = 0;
951 res = LoadKeyboardLayoutA(buf, Flags);
952 HeapFree( GetProcessHeap(), 0, buf );
953 return res;