Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello <abbeyj@wpi.edu>
[wine.git] / windows / input.c
blobf4416797e39a644ce2f491d1a9b6f06ef8ce3d44
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 "debugtools.h"
28 #include "struct32.h"
29 #include "winerror.h"
30 #include "task.h"
32 DECLARE_DEBUG_CHANNEL(accel)
33 DECLARE_DEBUG_CHANNEL(event)
34 DECLARE_DEBUG_CHANNEL(key)
35 DECLARE_DEBUG_CHANNEL(keyboard)
36 DECLARE_DEBUG_CHANNEL(win)
38 static BOOL InputEnabled = TRUE;
39 static BOOL SwappedButtons = FALSE;
41 BOOL MouseButtonsStates[3];
42 BOOL AsyncMouseButtonsStates[3];
43 BYTE InputKeyStateTable[256];
44 BYTE QueueKeyStateTable[256];
45 BYTE AsyncKeyStateTable[256];
47 typedef union
49 struct
51 unsigned long count : 16;
52 unsigned long code : 8;
53 unsigned long extended : 1;
54 unsigned long unused : 2;
55 unsigned long win_internal : 2;
56 unsigned long context : 1;
57 unsigned long previous : 1;
58 unsigned long transition : 1;
59 } lp1;
60 unsigned long lp2;
61 } KEYLP;
63 /***********************************************************************
64 * keybd_event (USER32.583)
66 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
67 DWORD dwFlags, DWORD dwExtraInfo )
69 DWORD posX, posY, time, extra;
70 WORD message;
71 KEYLP keylp;
72 keylp.lp2 = 0;
74 if (!InputEnabled) return;
77 * If we are called by the Wine keyboard driver, use the additional
78 * info pointed to by the dwExtraInfo argument.
79 * Otherwise, we need to determine that info ourselves (probably
80 * less accurate, but we can't help that ...).
82 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_KEYBDEVENT) )
83 && ((WINE_KEYBDEVENT *)dwExtraInfo)->magic == WINE_KEYBDEVENT_MAGIC )
85 WINE_KEYBDEVENT *wke = (WINE_KEYBDEVENT *)dwExtraInfo;
86 posX = wke->posX;
87 posY = wke->posY;
88 time = wke->time;
89 extra = 0;
91 else
93 DWORD keyState;
94 time = GetTickCount();
95 extra = dwExtraInfo;
97 if ( !EVENT_QueryPointer( &posX, &posY, &keyState ))
98 return;
102 keylp.lp1.count = 1;
103 keylp.lp1.code = bScan;
104 keylp.lp1.extended = (dwFlags & KEYEVENTF_EXTENDEDKEY) != 0;
105 keylp.lp1.win_internal = 0; /* this has something to do with dialogs,
106 * don't remember where I read it - AK */
107 /* it's '1' under windows, when a dialog box appears
108 * and you press one of the underlined keys - DF*/
110 if ( dwFlags & KEYEVENTF_KEYUP )
112 BOOL sysKey = (InputKeyStateTable[VK_MENU] & 0x80)
113 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
114 && !(dwFlags & KEYEVENTF_WINE_FORCEEXTENDED); /* for Alt from AltGr */
116 InputKeyStateTable[bVk] &= ~0x80;
117 keylp.lp1.previous = 1;
118 keylp.lp1.transition = 1;
119 message = sysKey ? WM_SYSKEYUP : WM_KEYUP;
121 else
123 keylp.lp1.previous = (InputKeyStateTable[bVk] & 0x80) != 0;
124 keylp.lp1.transition = 0;
126 if (!(InputKeyStateTable[bVk] & 0x80))
127 InputKeyStateTable[bVk] ^= 0x01;
128 InputKeyStateTable[bVk] |= 0x80;
130 message = (InputKeyStateTable[VK_MENU] & 0x80)
131 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
132 ? WM_SYSKEYDOWN : WM_KEYDOWN;
135 if ( message == WM_SYSKEYDOWN || message == WM_SYSKEYUP )
136 keylp.lp1.context = (InputKeyStateTable[VK_MENU] & 0x80) != 0; /* 1 if alt */
139 TRACE_(key)(" wParam=%04X, lParam=%08lX\n", bVk, keylp.lp2 );
140 TRACE_(key)(" InputKeyState=%X\n", InputKeyStateTable[bVk] );
142 hardware_event( message, bVk, keylp.lp2, posX, posY, time, extra );
145 /***********************************************************************
146 * mouse_event (USER32.584)
148 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
149 DWORD cButtons, DWORD dwExtraInfo )
151 DWORD posX, posY, keyState, time, extra;
153 if (!InputEnabled) return;
156 * If we are called by the Wine mouse driver, use the additional
157 * info pointed to by the dwExtraInfo argument.
158 * Otherwise, we need to determine that info ourselves (probably
159 * less accurate, but we can't help that ...).
161 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_MOUSEEVENT) )
162 && ((WINE_MOUSEEVENT *)dwExtraInfo)->magic == WINE_MOUSEEVENT_MAGIC )
164 WINE_MOUSEEVENT *wme = (WINE_MOUSEEVENT *)dwExtraInfo;
165 keyState = wme->keyState;
166 time = wme->time;
167 extra = (DWORD)wme->hWnd;
169 assert( dwFlags & MOUSEEVENTF_ABSOLUTE );
170 posX = (dx * GetSystemMetrics(SM_CXSCREEN)) >> 16;
171 posY = (dy * GetSystemMetrics(SM_CYSCREEN)) >> 16;
173 else
175 time = GetTickCount();
176 extra = dwExtraInfo;
178 if ( !EVENT_QueryPointer( &posX, &posY, &keyState ))
179 return;
181 if ( dwFlags & MOUSEEVENTF_MOVE )
183 if ( dwFlags & MOUSEEVENTF_ABSOLUTE )
185 posX = (dx * GetSystemMetrics(SM_CXSCREEN)) >> 16;
186 posY = (dy * GetSystemMetrics(SM_CYSCREEN)) >> 16;
188 else
190 posX += dx;
191 posY += dy;
193 /* We have to actually move the cursor */
194 SetCursorPos( posX, posY );
198 if ( dwFlags & MOUSEEVENTF_MOVE )
200 hardware_event( WM_MOUSEMOVE,
201 keyState, 0L, posX, posY, time, extra );
203 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN) )
205 MouseButtonsStates[0] = AsyncMouseButtonsStates[0] = TRUE;
206 hardware_event( WM_LBUTTONDOWN,
207 keyState, 0L, posX, posY, time, extra );
209 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP) )
211 MouseButtonsStates[0] = FALSE;
212 hardware_event( WM_LBUTTONUP,
213 keyState, 0L, posX, posY, time, extra );
215 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN) )
217 MouseButtonsStates[2] = AsyncMouseButtonsStates[2] = TRUE;
218 hardware_event( WM_RBUTTONDOWN,
219 keyState, 0L, posX, posY, time, extra );
221 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_LEFTUP) )
223 MouseButtonsStates[2] = FALSE;
224 hardware_event( WM_RBUTTONUP,
225 keyState, 0L, posX, posY, time, extra );
227 if ( dwFlags & MOUSEEVENTF_MIDDLEDOWN )
229 MouseButtonsStates[1] = AsyncMouseButtonsStates[1] = TRUE;
230 hardware_event( WM_MBUTTONDOWN,
231 keyState, 0L, posX, posY, time, extra );
233 if ( dwFlags & MOUSEEVENTF_MIDDLEUP )
235 MouseButtonsStates[1] = FALSE;
236 hardware_event( WM_MBUTTONUP,
237 keyState, 0L, posX, posY, time, extra );
241 /**********************************************************************
242 * EnableHardwareInput (USER.331)
244 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
246 BOOL16 bOldState = InputEnabled;
247 FIXME_(event)("(%d) - stub\n", bEnable);
248 InputEnabled = bEnable;
249 return bOldState;
253 /***********************************************************************
254 * SwapMouseButton16 (USER.186)
256 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
258 BOOL16 ret = SwappedButtons;
259 SwappedButtons = fSwap;
260 return ret;
264 /***********************************************************************
265 * SwapMouseButton32 (USER32.537)
267 BOOL WINAPI SwapMouseButton( BOOL fSwap )
269 BOOL ret = SwappedButtons;
270 SwappedButtons = fSwap;
271 return ret;
274 /**********************************************************************
275 * EVENT_Capture
277 * We need this to be able to generate double click messages
278 * when menu code captures mouse in the window without CS_DBLCLK style.
280 HWND EVENT_Capture(HWND hwnd, INT16 ht)
282 HWND capturePrev = 0, captureWnd = 0;
283 MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0;
284 WND* wndPtr = 0;
285 INT16 captureHT = 0;
287 /* Get the messageQ for the current thread */
288 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
290 WARN_(win)("\tCurrent message queue not found. Exiting!\n" );
291 goto CLEANUP;
294 /* Get the current capture window from the perQ data of the current message Q */
295 capturePrev = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
297 if (!hwnd)
299 captureWnd = 0L;
300 captureHT = 0;
302 else
304 wndPtr = WIN_FindWndPtr( hwnd );
305 if (wndPtr)
307 TRACE_(win)("(0x%04x)\n", hwnd );
308 captureWnd = hwnd;
309 captureHT = ht;
313 /* Update the perQ capture window and send messages */
314 if( capturePrev != captureWnd )
316 if (wndPtr)
318 /* Retrieve the message queue associated with this window */
319 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
320 if ( !pMsgQ )
322 WARN_(win)("\tMessage queue not found. Exiting!\n" );
323 goto CLEANUP;
326 /* Make sure that message queue for the window we are setting capture to
327 * shares the same perQ data as the current threads message queue.
329 if ( pCurMsgQ->pQData != pMsgQ->pQData )
330 goto CLEANUP;
333 PERQDATA_SetCaptureWnd( pCurMsgQ->pQData, captureWnd );
334 PERQDATA_SetCaptureInfo( pCurMsgQ->pQData, captureHT );
336 if( capturePrev )
338 WND* wndPtr = WIN_FindWndPtr( capturePrev );
339 if( wndPtr && (wndPtr->flags & WIN_ISWIN32) )
340 SendMessageA( capturePrev, WM_CAPTURECHANGED, 0L, hwnd);
341 WIN_ReleaseWndPtr(wndPtr);
345 CLEANUP:
346 /* Unlock the queues before returning */
347 if ( pMsgQ )
348 QUEUE_Unlock( pMsgQ );
349 if ( pCurMsgQ )
350 QUEUE_Unlock( pCurMsgQ );
352 WIN_ReleaseWndPtr(wndPtr);
353 return capturePrev;
357 /**********************************************************************
358 * SetCapture16 (USER.18)
360 HWND16 WINAPI SetCapture16( HWND16 hwnd )
362 return (HWND16)EVENT_Capture( hwnd, HTCLIENT );
366 /**********************************************************************
367 * SetCapture32 (USER32.464)
369 HWND WINAPI SetCapture( HWND hwnd )
371 return EVENT_Capture( hwnd, HTCLIENT );
375 /**********************************************************************
376 * ReleaseCapture (USER.19) (USER32.439)
378 BOOL WINAPI ReleaseCapture(void)
380 return (EVENT_Capture( 0, 0 ) != 0);
384 /**********************************************************************
385 * GetCapture16 (USER.236)
387 HWND16 WINAPI GetCapture16(void)
389 return (HWND16)GetCapture();
392 /**********************************************************************
393 * GetCapture32 (USER32.208)
395 HWND WINAPI GetCapture(void)
397 MESSAGEQUEUE *pCurMsgQ = 0;
398 HWND hwndCapture = 0;
400 /* Get the messageQ for the current thread */
401 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
403 TRACE_(win)("GetCapture32: Current message queue not found. Exiting!\n" );
404 return 0;
407 /* Get the current capture window from the perQ data of the current message Q */
408 hwndCapture = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
410 QUEUE_Unlock( pCurMsgQ );
411 return hwndCapture;
414 /**********************************************************************
415 * GetKeyState (USER.106)
417 INT16 WINAPI GetKeyState16(INT16 vkey)
419 return GetKeyState(vkey);
422 /**********************************************************************
423 * GetKeyState (USER32.249)
425 * An application calls the GetKeyState function in response to a
426 * keyboard-input message. This function retrieves the state of the key
427 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
429 INT16 WINAPI GetKeyState(INT vkey)
431 INT retval;
433 switch (vkey)
435 case VK_LBUTTON : /* VK_LBUTTON is 1 */
436 retval = MouseButtonsStates[0] ? 0x8000 : 0;
437 break;
438 case VK_MBUTTON : /* VK_MBUTTON is 4 */
439 retval = MouseButtonsStates[1] ? 0x8000 : 0;
440 break;
441 case VK_RBUTTON : /* VK_RBUTTON is 2 */
442 retval = MouseButtonsStates[2] ? 0x8000 : 0;
443 break;
444 default :
445 if (vkey >= 'a' && vkey <= 'z')
446 vkey += 'A' - 'a';
447 retval = ( (WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
448 (WORD)(QueueKeyStateTable[vkey] & 0x01);
450 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
451 return retval;
454 /**********************************************************************
455 * GetKeyboardState (USER.222)(USER32.254)
457 * An application calls the GetKeyboardState function in response to a
458 * keyboard-input message. This function retrieves the state of the keyboard
459 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
461 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
463 TRACE_(key)("(%p)\n", lpKeyState);
464 if (lpKeyState != NULL) {
465 QueueKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
466 QueueKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
467 QueueKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
468 memcpy(lpKeyState, QueueKeyStateTable, 256);
471 return TRUE;
474 /**********************************************************************
475 * SetKeyboardState (USER.223)(USER32.484)
477 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
479 TRACE_(key)("(%p)\n", lpKeyState);
480 if (lpKeyState != NULL) {
481 memcpy(QueueKeyStateTable, lpKeyState, 256);
482 MouseButtonsStates[0] = (QueueKeyStateTable[VK_LBUTTON] != 0);
483 MouseButtonsStates[1] = (QueueKeyStateTable[VK_MBUTTON] != 0);
484 MouseButtonsStates[2] = (QueueKeyStateTable[VK_RBUTTON] != 0);
487 return TRUE;
490 /**********************************************************************
491 * GetAsyncKeyState32 (USER32.207)
493 * Determine if a key is or was pressed. retval has high-order
494 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
495 * been pressed.
497 * This uses the variable AsyncMouseButtonsStates and
498 * AsyncKeyStateTable (set in event.c) which have the mouse button
499 * number or key number (whichever is applicable) set to true if the
500 * mouse or key had been depressed since the last call to
501 * GetAsyncKeyState.
503 WORD WINAPI GetAsyncKeyState(INT nKey)
505 short retval;
507 switch (nKey) {
508 case VK_LBUTTON:
509 retval = (AsyncMouseButtonsStates[0] ? 0x0001 : 0) |
510 (MouseButtonsStates[0] ? 0x8000 : 0);
511 break;
512 case VK_MBUTTON:
513 retval = (AsyncMouseButtonsStates[1] ? 0x0001 : 0) |
514 (MouseButtonsStates[1] ? 0x8000 : 0);
515 break;
516 case VK_RBUTTON:
517 retval = (AsyncMouseButtonsStates[2] ? 0x0001 : 0) |
518 (MouseButtonsStates[2] ? 0x8000 : 0);
519 break;
520 default:
521 retval = AsyncKeyStateTable[nKey] |
522 ((InputKeyStateTable[nKey] & 0x80) ? 0x8000 : 0);
523 break;
526 /* all states to false */
527 memset( AsyncMouseButtonsStates, 0, sizeof(AsyncMouseButtonsStates) );
528 memset( AsyncKeyStateTable, 0, sizeof(AsyncKeyStateTable) );
530 TRACE_(key)("(%x) -> %x\n", nKey, retval);
531 return retval;
534 /**********************************************************************
535 * GetAsyncKeyState16 (USER.249)
537 WORD WINAPI GetAsyncKeyState16(INT16 nKey)
539 return GetAsyncKeyState(nKey);
542 /**********************************************************************
543 * KBD_translate_accelerator
545 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
547 static BOOL KBD_translate_accelerator(HWND hWnd,LPMSG msg,
548 BYTE fVirt,WORD key,WORD cmd)
550 BOOL sendmsg = FALSE;
552 if(msg->wParam == key)
554 if (msg->message == WM_CHAR) {
555 if ( !(fVirt & FALT) && !(fVirt & FVIRTKEY) )
557 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n",
558 msg->wParam&0xff);
559 sendmsg=TRUE;
561 } else {
562 if(fVirt & FVIRTKEY) {
563 INT mask = 0;
564 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
565 msg->wParam,0xff & HIWORD(msg->lParam));
566 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
567 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
568 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
569 if(mask == (fVirt & (FSHIFT | FCONTROL | FALT)))
570 sendmsg=TRUE;
571 else
572 TRACE_(accel)(", but incorrect SHIFT/CTRL/ALT-state\n");
574 else
576 if (!(msg->lParam & 0x01000000)) /* no special_key */
578 if ((fVirt & FALT) && (msg->lParam & 0x20000000))
579 { /* ^^ ALT pressed */
580 TRACE_(accel)("found accel for Alt-%c\n", msg->wParam&0xff);
581 sendmsg=TRUE;
587 if (sendmsg) /* found an accelerator, but send a message... ? */
589 INT16 iSysStat,iStat,mesg=0;
590 HMENU16 hMenu;
592 if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
593 mesg=1;
594 else
595 if (GetCapture())
596 mesg=2;
597 else
598 if (!IsWindowEnabled(hWnd))
599 mesg=3;
600 else
602 WND* wndPtr = WIN_FindWndPtr(hWnd);
604 hMenu = (wndPtr->dwStyle & WS_CHILD) ? 0 : (HMENU)wndPtr->wIDmenu;
605 iSysStat = (wndPtr->hSysMenu) ? GetMenuState(GetSubMenu16(wndPtr->hSysMenu, 0),
606 cmd, MF_BYCOMMAND) : -1 ;
607 iStat = (hMenu) ? GetMenuState(hMenu,
608 cmd, MF_BYCOMMAND) : -1 ;
610 WIN_ReleaseWndPtr(wndPtr);
612 if (iSysStat!=-1)
614 if (iSysStat & (MF_DISABLED|MF_GRAYED))
615 mesg=4;
616 else
617 mesg=WM_SYSCOMMAND;
619 else
621 if (iStat!=-1)
623 if (IsIconic(hWnd))
624 mesg=5;
625 else
627 if (iStat & (MF_DISABLED|MF_GRAYED))
628 mesg=6;
629 else
630 mesg=WM_COMMAND;
633 else
634 mesg=WM_COMMAND;
637 if ( mesg==WM_COMMAND || mesg==WM_SYSCOMMAND )
639 TRACE_(accel)(", sending %s, wParam=%0x\n",
640 mesg==WM_COMMAND ? "WM_COMMAND" : "WM_SYSCOMMAND",
641 cmd);
642 SendMessageA(hWnd, mesg, cmd, 0x00010000L);
644 else
646 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
647 * #0: unknown (please report!)
648 * #1: for WM_KEYUP,WM_SYSKEYUP
649 * #2: mouse is captured
650 * #3: window is disabled
651 * #4: it's a disabled system menu option
652 * #5: it's a menu option, but window is iconic
653 * #6: it's a menu option, but disabled
655 TRACE_(accel)(", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg);
656 if(mesg==0)
657 ERR_(accel)(" unknown reason - please report!");
659 return TRUE;
662 return FALSE;
665 /**********************************************************************
666 * TranslateAccelerator32 (USER32.551)(USER32.552)(USER32.553)
668 INT WINAPI TranslateAccelerator(HWND hWnd, HACCEL hAccel, LPMSG msg)
670 /* YES, Accel16! */
671 LPACCEL16 lpAccelTbl = (LPACCEL16)LockResource16(hAccel);
672 int i;
674 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);
676 if (hAccel == 0 || msg == NULL ||
677 (msg->message != WM_KEYDOWN &&
678 msg->message != WM_KEYUP &&
679 msg->message != WM_SYSKEYDOWN &&
680 msg->message != WM_SYSKEYUP &&
681 msg->message != WM_CHAR)) {
682 WARN_(accel)("erraneous input parameters\n");
683 SetLastError(ERROR_INVALID_PARAMETER);
684 return 0;
687 TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,"
688 "msg->hwnd=%04x, msg->message=%04x\n",
689 hAccel,hWnd,msg->hwnd,msg->message);
691 i = 0;
694 if (KBD_translate_accelerator(hWnd,msg,lpAccelTbl[i].fVirt,
695 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
696 return 1;
697 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
698 WARN_(accel)("couldn't translate accelerator key\n");
699 return 0;
702 /**********************************************************************
703 * TranslateAccelerator16 (USER.178)
705 INT16 WINAPI TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
707 LPACCEL16 lpAccelTbl = (LPACCEL16)LockResource16(hAccel);
708 int i;
709 MSG msg32;
711 if (hAccel == 0 || msg == NULL ||
712 (msg->message != WM_KEYDOWN &&
713 msg->message != WM_KEYUP &&
714 msg->message != WM_SYSKEYDOWN &&
715 msg->message != WM_SYSKEYUP &&
716 msg->message != WM_CHAR)) {
717 WARN_(accel)("erraneous input parameters\n");
718 SetLastError(ERROR_INVALID_PARAMETER);
719 return 0;
722 TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,\
723 msg->hwnd=%04x, msg->message=%04x\n", hAccel,hWnd,msg->hwnd,msg->message);
724 STRUCT32_MSG16to32(msg,&msg32);
727 i = 0;
730 if (KBD_translate_accelerator(hWnd,&msg32,lpAccelTbl[i].fVirt,
731 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
732 return 1;
733 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
734 WARN_(accel)("couldn't translate accelerator key\n");
735 return 0;
739 /**********************************************************************
740 * VkKeyScanA (USER32.573)
742 WORD WINAPI VkKeyScanA(CHAR cChar)
744 return VkKeyScan16(cChar);
747 /******************************************************************************
748 * VkKeyScanW (USER32.576)
750 WORD WINAPI VkKeyScanW(WCHAR cChar)
752 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
755 /**********************************************************************
756 * VkKeyScanExA (USER32.574)
758 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
760 /* FIXME: complete workaround this is */
761 return VkKeyScan16(cChar);
764 /******************************************************************************
765 * VkKeyScanExW (USER32.575)
767 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
769 /* FIXME: complete workaround this is */
770 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
773 /******************************************************************************
774 * GetKeyboardType32 (USER32.255)
776 INT WINAPI GetKeyboardType(INT nTypeFlag)
778 return GetKeyboardType16(nTypeFlag);
781 /******************************************************************************
782 * MapVirtualKey32A (USER32.383)
784 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
786 return MapVirtualKey16(code,maptype);
789 /******************************************************************************
790 * MapVirtualKey32W (USER32.385)
792 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
794 return MapVirtualKey16(code,maptype);
797 /******************************************************************************
798 * MapVirtualKeyEx32A (USER32.384)
800 UINT WINAPI MapVirtualKeyEx32A(UINT code, UINT maptype, HKL hkl)
802 if (hkl)
803 FIXME_(keyboard)("(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
804 return MapVirtualKey16(code,maptype);
807 /****************************************************************************
808 * GetKBCodePage32 (USER32.246)
810 UINT WINAPI GetKBCodePage(void)
812 return GetKBCodePage16();
815 /****************************************************************************
816 * GetKeyboardLayoutName16 (USER.477)
818 INT16 WINAPI GetKeyboardLayoutName16(LPSTR pwszKLID)
820 return GetKeyboardLayoutNameA(pwszKLID);
823 /***********************************************************************
824 * GetKeyboardLayout (USER32.250)
826 * FIXME: - device handle for keyboard layout defaulted to
827 * the language id. This is the way Windows default works.
828 * - the thread identifier (dwLayout) is also ignored.
830 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
832 HKL layout;
833 layout = GetSystemDefaultLCID(); /* FIXME */
834 layout |= (layout<<16); /* FIXME */
835 TRACE_(keyboard)("returning %08x\n",layout);
836 return layout;
839 /****************************************************************************
840 * GetKeyboardLayoutName32A (USER32.252)
842 INT WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID)
844 sprintf(pwszKLID, "%08x",GetKeyboardLayout(0));
845 return 1;
848 /****************************************************************************
849 * GetKeyboardLayoutName32W (USER32.253)
851 INT WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
853 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
854 int res = GetKeyboardLayoutNameA(buf);
855 lstrcpyAtoW(pwszKLID,buf);
856 HeapFree( GetProcessHeap(), 0, buf );
857 return res;
860 /****************************************************************************
861 * GetKeyNameText32A (USER32.247)
863 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
865 return GetKeyNameText16(lParam,lpBuffer,nSize);
868 /****************************************************************************
869 * GetKeyNameText32W (USER32.248)
871 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
873 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, nSize );
874 int res = GetKeyNameTextA(lParam,buf,nSize);
876 lstrcpynAtoW(lpBuffer,buf,nSize);
877 HeapFree( GetProcessHeap(), 0, buf );
878 return res;
881 /****************************************************************************
882 * ToAscii32 (USER32.546)
884 INT WINAPI ToAscii( UINT virtKey,UINT scanCode,LPBYTE lpKeyState,
885 LPWORD lpChar,UINT flags )
887 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
890 /****************************************************************************
891 * ToAscii32 (USER32.547)
893 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
894 LPWORD lpChar, UINT flags, HKL dwhkl )
896 /* FIXME: need true implementation */
897 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
900 /**********************************************************************
901 * ActivateKeyboardLayout32 (USER32.1)
903 * Call ignored. WINE supports only system default keyboard layout.
905 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
907 TRACE_(keyboard)("(%d, %d)\n", hLayout, flags);
908 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
909 return 0;
913 /***********************************************************************
914 * GetKeyboardLayoutList (USER32.251)
916 * FIXME: Supports only the system default language and layout and
917 * returns only 1 value.
919 * Return number of values available if either input parm is
920 * 0, per MS documentation.
923 INT WINAPI GetKeyboardLayoutList(INT nBuff,HKL *layouts)
925 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
926 if (!nBuff || !layouts)
927 return 1;
928 if (layouts)
929 layouts[0] = GetKeyboardLayout(0);
930 return 1;
934 /***********************************************************************
935 * RegisterHotKey (USER32.433)
937 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk) {
938 FIXME_(keyboard)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
939 return TRUE;
942 /***********************************************************************
943 * UnregisterHotKey (USER32.565)
945 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id) {
946 FIXME_(keyboard)("(0x%08x,%d): stub\n",hwnd,id);
947 return TRUE;
951 /***********************************************************************
952 * ToUnicode32 (USER32.548)
954 INT WINAPI ToUnicode(
955 UINT wVirtKey,
956 UINT wScanCode,
957 PBYTE lpKeyState,
958 LPWSTR pwszBuff,
959 int cchBuff,
960 UINT wFlags) {
962 FIXME_(keyboard)(": stub\n");
963 return 0;
966 /***********************************************************************
967 * LoadKeyboardLayout32A (USER32.367)
968 * Call ignored. WINE supports only system default keyboard layout.
970 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
972 TRACE_(keyboard)("(%s, %d)\n", pwszKLID, Flags);
973 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
974 return 0;
977 /***********************************************************************
978 * LoadKeyboardLayout32W (USER32.368)
980 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
982 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
983 int res;
984 lstrcpynWtoA(buf,pwszKLID,8);
985 buf[8] = 0;
986 res = LoadKeyboardLayoutA(buf, Flags);
987 HeapFree( GetProcessHeap(), 0, buf );
988 return res;