2 * USER Input processing
4 * Copyright 1993 Bob Amstadt
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1997 David Faure
7 * Copyright 1998 Morten Welinder
8 * Copyright 1998 Ulrich Weigand
21 #include "wine/winbase16.h"
22 #include "wine/winuser16.h"
23 #include "wine/keyboard16.h"
31 #include "debugtools.h"
36 DECLARE_DEBUG_CHANNEL(accel
);
37 DECLARE_DEBUG_CHANNEL(event
);
38 DECLARE_DEBUG_CHANNEL(key
);
39 DECLARE_DEBUG_CHANNEL(keyboard
);
40 DECLARE_DEBUG_CHANNEL(win
);
42 static BOOL InputEnabled
= TRUE
;
43 BOOL SwappedButtons
= FALSE
;
45 BOOL MouseButtonsStates
[3];
46 BOOL AsyncMouseButtonsStates
[3];
47 BYTE InputKeyStateTable
[256];
48 BYTE QueueKeyStateTable
[256];
49 BYTE AsyncKeyStateTable
[256];
51 /* Storage for the USER-maintained mouse positions */
58 unsigned long count
: 16;
59 unsigned long code
: 8;
60 unsigned long extended
: 1;
61 unsigned long unused
: 2;
62 unsigned long win_internal
: 2;
63 unsigned long context
: 1;
64 unsigned long previous
: 1;
65 unsigned long transition
: 1;
70 /***********************************************************************
71 * keybd_event (USER32.583)
73 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
74 DWORD dwFlags
, DWORD dwExtraInfo
)
81 if (!InputEnabled
) return;
84 * If we are called by the Wine keyboard driver, use the additional
85 * info pointed to by the dwExtraInfo argument.
86 * Otherwise, we need to determine that info ourselves (probably
87 * less accurate, but we can't help that ...).
89 if ( !IsBadReadPtr( (LPVOID
)dwExtraInfo
, sizeof(WINE_KEYBDEVENT
) )
90 && ((WINE_KEYBDEVENT
*)dwExtraInfo
)->magic
== WINE_KEYBDEVENT_MAGIC
)
92 WINE_KEYBDEVENT
*wke
= (WINE_KEYBDEVENT
*)dwExtraInfo
;
98 time
= GetTickCount();
104 keylp
.lp1
.code
= bScan
;
105 keylp
.lp1
.extended
= (dwFlags
& KEYEVENTF_EXTENDEDKEY
) != 0;
106 keylp
.lp1
.win_internal
= 0; /* this has something to do with dialogs,
107 * don't remember where I read it - AK */
108 /* it's '1' under windows, when a dialog box appears
109 * and you press one of the underlined keys - DF*/
111 if ( dwFlags
& KEYEVENTF_KEYUP
)
113 BOOL sysKey
= (InputKeyStateTable
[VK_MENU
] & 0x80)
114 && !(InputKeyStateTable
[VK_CONTROL
] & 0x80)
115 && !(dwFlags
& KEYEVENTF_WINE_FORCEEXTENDED
); /* for Alt from AltGr */
117 InputKeyStateTable
[bVk
] &= ~0x80;
118 keylp
.lp1
.previous
= 1;
119 keylp
.lp1
.transition
= 1;
120 message
= sysKey
? WM_SYSKEYUP
: WM_KEYUP
;
124 keylp
.lp1
.previous
= (InputKeyStateTable
[bVk
] & 0x80) != 0;
125 keylp
.lp1
.transition
= 0;
127 if (!(InputKeyStateTable
[bVk
] & 0x80))
128 InputKeyStateTable
[bVk
] ^= 0x01;
129 InputKeyStateTable
[bVk
] |= 0x80;
131 message
= (InputKeyStateTable
[VK_MENU
] & 0x80)
132 && !(InputKeyStateTable
[VK_CONTROL
] & 0x80)
133 ? WM_SYSKEYDOWN
: WM_KEYDOWN
;
136 if ( message
== WM_SYSKEYDOWN
|| message
== WM_SYSKEYUP
)
137 keylp
.lp1
.context
= (InputKeyStateTable
[VK_MENU
] & 0x80) != 0; /* 1 if alt */
140 TRACE_(key
)(" wParam=%04X, lParam=%08lX\n", bVk
, keylp
.lp2
);
141 TRACE_(key
)(" InputKeyState=%X\n", InputKeyStateTable
[bVk
] );
143 hardware_event( message
, bVk
, keylp
.lp2
, PosX
, PosY
, time
, extra
);
146 /***********************************************************************
147 * WIN16_keybd_event (USER.289)
149 void WINAPI
WIN16_keybd_event( CONTEXT86
*context
)
153 if (AH_reg(context
) & 0x80) dwFlags
|= KEYEVENTF_KEYUP
;
154 if (BH_reg(context
) & 1 ) dwFlags
|= KEYEVENTF_EXTENDEDKEY
;
156 keybd_event( AL_reg(context
), BL_reg(context
),
157 dwFlags
, MAKELONG(SI_reg(context
), DI_reg(context
)) );
160 /***********************************************************************
161 * mouse_event (USER32.584)
163 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
164 DWORD cButtons
, DWORD dwExtraInfo
)
169 if (!InputEnabled
) return;
171 if ( dwFlags
& MOUSEEVENTF_MOVE
)
173 if ( dwFlags
& MOUSEEVENTF_ABSOLUTE
)
175 PosX
= (dx
* GetSystemMetrics(SM_CXSCREEN
)) >> 16;
176 PosY
= (dy
* GetSystemMetrics(SM_CYSCREEN
)) >> 16;
180 int width
= GetSystemMetrics(SM_CXSCREEN
);
181 int height
= GetSystemMetrics(SM_CYSCREEN
);
182 long posX
= (long) PosX
, posY
= (long) PosY
;
184 /* dx and dy can be negative numbers for relative movements */
188 /* Clip to the current screen size */
189 if (posX
< 0) PosX
= 0;
190 else if (posX
>= width
) PosX
= width
- 1;
193 if (posY
< 0) PosY
= 0;
194 else if (posY
>= height
) PosY
= height
- 1;
200 * If we are called by the Wine mouse driver, use the additional
201 * info pointed to by the dwExtraInfo argument.
202 * Otherwise, we need to determine that info ourselves (probably
203 * less accurate, but we can't help that ...).
205 if ( !IsBadReadPtr( (LPVOID
)dwExtraInfo
, sizeof(WINE_MOUSEEVENT
) )
206 && ((WINE_MOUSEEVENT
*)dwExtraInfo
)->magic
== WINE_MOUSEEVENT_MAGIC
)
208 WINE_MOUSEEVENT
*wme
= (WINE_MOUSEEVENT
*)dwExtraInfo
;
210 extra
= (DWORD
)wme
->hWnd
;
211 keyState
= wme
->keyState
;
213 if (keyState
!= GET_KEYSTATE()) {
214 /* We need to update the keystate with what X provides us */
215 MouseButtonsStates
[SwappedButtons
? 2 : 0] = (keyState
& MK_LBUTTON
? TRUE
: FALSE
);
216 MouseButtonsStates
[SwappedButtons
? 0 : 2] = (keyState
& MK_RBUTTON
? TRUE
: FALSE
);
217 MouseButtonsStates
[1] = (keyState
& MK_MBUTTON
? TRUE
: FALSE
);
218 InputKeyStateTable
[VK_SHIFT
] = (keyState
& MK_SHIFT
? 0x80 : 0);
219 InputKeyStateTable
[VK_CONTROL
] = (keyState
& MK_CONTROL
? 0x80 : 0);
224 time
= GetTickCount();
226 keyState
= GET_KEYSTATE();
228 if ( dwFlags
& MOUSEEVENTF_MOVE
)
230 /* We have to actually move the cursor */
231 SetCursorPos( PosX
, PosY
);
236 if ( dwFlags
& MOUSEEVENTF_MOVE
)
238 hardware_event( WM_MOUSEMOVE
,
239 keyState
, 0L, PosX
, PosY
, time
, extra
);
241 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_RIGHTDOWN
) )
243 MouseButtonsStates
[0] = AsyncMouseButtonsStates
[0] = TRUE
;
244 hardware_event( WM_LBUTTONDOWN
,
245 keyState
, 0L, PosX
, PosY
, time
, extra
);
247 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_LEFTUP
: MOUSEEVENTF_RIGHTUP
) )
249 MouseButtonsStates
[0] = FALSE
;
250 hardware_event( WM_LBUTTONUP
,
251 keyState
, 0L, PosX
, PosY
, time
, extra
);
253 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_RIGHTDOWN
: MOUSEEVENTF_LEFTDOWN
) )
255 MouseButtonsStates
[2] = AsyncMouseButtonsStates
[2] = TRUE
;
256 hardware_event( WM_RBUTTONDOWN
,
257 keyState
, 0L, PosX
, PosY
, time
, extra
);
259 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_RIGHTUP
: MOUSEEVENTF_LEFTUP
) )
261 MouseButtonsStates
[2] = FALSE
;
262 hardware_event( WM_RBUTTONUP
,
263 keyState
, 0L, PosX
, PosY
, time
, extra
);
265 if ( dwFlags
& MOUSEEVENTF_MIDDLEDOWN
)
267 MouseButtonsStates
[1] = AsyncMouseButtonsStates
[1] = TRUE
;
268 hardware_event( WM_MBUTTONDOWN
,
269 keyState
, 0L, PosX
, PosY
, time
, extra
);
271 if ( dwFlags
& MOUSEEVENTF_MIDDLEUP
)
273 MouseButtonsStates
[1] = FALSE
;
274 hardware_event( WM_MBUTTONUP
,
275 keyState
, 0L, PosX
, PosY
, time
, extra
);
279 /***********************************************************************
280 * WIN16_mouse_event (USER.299)
282 void WINAPI
WIN16_mouse_event( CONTEXT86
*context
)
284 mouse_event( AX_reg(context
), BX_reg(context
), CX_reg(context
),
285 DX_reg(context
), MAKELONG(SI_reg(context
), DI_reg(context
)) );
288 /***********************************************************************
289 * GetMouseEventProc (USER.337)
291 FARPROC16 WINAPI
GetMouseEventProc16(void)
293 HMODULE16 hmodule
= GetModuleHandle16("USER");
294 return NE_GetEntryPoint( hmodule
, NE_GetOrdinal( hmodule
, "mouse_event" ));
298 /**********************************************************************
299 * EnableHardwareInput (USER.331)
301 BOOL16 WINAPI
EnableHardwareInput16(BOOL16 bEnable
)
303 BOOL16 bOldState
= InputEnabled
;
304 FIXME_(event
)("(%d) - stub\n", bEnable
);
305 InputEnabled
= bEnable
;
310 /***********************************************************************
311 * SwapMouseButton16 (USER.186)
313 BOOL16 WINAPI
SwapMouseButton16( BOOL16 fSwap
)
315 BOOL16 ret
= SwappedButtons
;
316 SwappedButtons
= fSwap
;
321 /***********************************************************************
322 * SwapMouseButton32 (USER32.537)
324 BOOL WINAPI
SwapMouseButton( BOOL fSwap
)
326 BOOL ret
= SwappedButtons
;
327 SwappedButtons
= fSwap
;
331 /**********************************************************************
334 * We need this to be able to generate double click messages
335 * when menu code captures mouse in the window without CS_DBLCLK style.
337 HWND
EVENT_Capture(HWND hwnd
, INT16 ht
)
339 HWND capturePrev
= 0, captureWnd
= 0;
340 MESSAGEQUEUE
*pMsgQ
= 0, *pCurMsgQ
= 0;
344 /* Get the messageQ for the current thread */
345 if (!(pCurMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
347 WARN_(win
)("\tCurrent message queue not found. Exiting!\n" );
351 /* Get the current capture window from the perQ data of the current message Q */
352 capturePrev
= PERQDATA_GetCaptureWnd( pCurMsgQ
->pQData
);
361 wndPtr
= WIN_FindWndPtr( hwnd
);
364 TRACE_(win
)("(0x%04x)\n", hwnd
);
370 /* Update the perQ capture window and send messages */
371 if( capturePrev
!= captureWnd
)
375 /* Retrieve the message queue associated with this window */
376 pMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( wndPtr
->hmemTaskQ
);
379 WARN_(win
)("\tMessage queue not found. Exiting!\n" );
383 /* Make sure that message queue for the window we are setting capture to
384 * shares the same perQ data as the current threads message queue.
386 if ( pCurMsgQ
->pQData
!= pMsgQ
->pQData
)
390 PERQDATA_SetCaptureWnd( pCurMsgQ
->pQData
, captureWnd
);
391 PERQDATA_SetCaptureInfo( pCurMsgQ
->pQData
, captureHT
);
395 WND
* wndPtr
= WIN_FindWndPtr( capturePrev
);
396 if( wndPtr
&& (wndPtr
->flags
& WIN_ISWIN32
) )
397 SendMessageA( capturePrev
, WM_CAPTURECHANGED
, 0L, hwnd
);
398 WIN_ReleaseWndPtr(wndPtr
);
403 /* Unlock the queues before returning */
405 QUEUE_Unlock( pMsgQ
);
407 QUEUE_Unlock( pCurMsgQ
);
409 WIN_ReleaseWndPtr(wndPtr
);
414 /**********************************************************************
415 * SetCapture16 (USER.18)
417 HWND16 WINAPI
SetCapture16( HWND16 hwnd
)
419 return (HWND16
)EVENT_Capture( hwnd
, HTCLIENT
);
423 /**********************************************************************
424 * SetCapture32 (USER32.464)
426 HWND WINAPI
SetCapture( HWND hwnd
)
428 return EVENT_Capture( hwnd
, HTCLIENT
);
432 /**********************************************************************
433 * ReleaseCapture (USER.19) (USER32.439)
435 BOOL WINAPI
ReleaseCapture(void)
437 return (EVENT_Capture( 0, 0 ) != 0);
441 /**********************************************************************
442 * GetCapture16 (USER.236)
444 HWND16 WINAPI
GetCapture16(void)
446 return (HWND16
)GetCapture();
449 /**********************************************************************
450 * GetCapture32 (USER32.208)
452 HWND WINAPI
GetCapture(void)
454 MESSAGEQUEUE
*pCurMsgQ
= 0;
455 HWND hwndCapture
= 0;
457 /* Get the messageQ for the current thread */
458 if (!(pCurMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
460 TRACE_(win
)("GetCapture32: Current message queue not found. Exiting!\n" );
464 /* Get the current capture window from the perQ data of the current message Q */
465 hwndCapture
= PERQDATA_GetCaptureWnd( pCurMsgQ
->pQData
);
467 QUEUE_Unlock( pCurMsgQ
);
471 /**********************************************************************
472 * GetKeyState (USER.106)
474 INT16 WINAPI
GetKeyState16(INT16 vkey
)
476 return GetKeyState(vkey
);
479 /**********************************************************************
480 * GetKeyState (USER32.249)
482 * An application calls the GetKeyState function in response to a
483 * keyboard-input message. This function retrieves the state of the key
484 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
486 SHORT WINAPI
GetKeyState(INT vkey
)
492 case VK_LBUTTON
: /* VK_LBUTTON is 1 */
493 retval
= MouseButtonsStates
[0] ? 0x8000 : 0;
495 case VK_MBUTTON
: /* VK_MBUTTON is 4 */
496 retval
= MouseButtonsStates
[1] ? 0x8000 : 0;
498 case VK_RBUTTON
: /* VK_RBUTTON is 2 */
499 retval
= MouseButtonsStates
[2] ? 0x8000 : 0;
502 if (vkey
>= 'a' && vkey
<= 'z')
504 retval
= ( (WORD
)(QueueKeyStateTable
[vkey
] & 0x80) << 8 ) |
505 (WORD
)(QueueKeyStateTable
[vkey
] & 0x01);
507 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
511 /**********************************************************************
512 * GetKeyboardState (USER.222)(USER32.254)
514 * An application calls the GetKeyboardState function in response to a
515 * keyboard-input message. This function retrieves the state of the keyboard
516 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
518 BOOL WINAPI
GetKeyboardState(LPBYTE lpKeyState
)
520 TRACE_(key
)("(%p)\n", lpKeyState
);
521 if (lpKeyState
!= NULL
) {
522 QueueKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] ? 0x80 : 0;
523 QueueKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] ? 0x80 : 0;
524 QueueKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] ? 0x80 : 0;
525 memcpy(lpKeyState
, QueueKeyStateTable
, 256);
531 /**********************************************************************
532 * SetKeyboardState (USER.223)(USER32.484)
534 BOOL WINAPI
SetKeyboardState(LPBYTE lpKeyState
)
536 TRACE_(key
)("(%p)\n", lpKeyState
);
537 if (lpKeyState
!= NULL
) {
538 memcpy(QueueKeyStateTable
, lpKeyState
, 256);
539 MouseButtonsStates
[0] = (QueueKeyStateTable
[VK_LBUTTON
] != 0);
540 MouseButtonsStates
[1] = (QueueKeyStateTable
[VK_MBUTTON
] != 0);
541 MouseButtonsStates
[2] = (QueueKeyStateTable
[VK_RBUTTON
] != 0);
547 /**********************************************************************
548 * GetAsyncKeyState32 (USER32.207)
550 * Determine if a key is or was pressed. retval has high-order
551 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
554 * This uses the variable AsyncMouseButtonsStates and
555 * AsyncKeyStateTable (set in event.c) which have the mouse button
556 * number or key number (whichever is applicable) set to true if the
557 * mouse or key had been depressed since the last call to
560 WORD WINAPI
GetAsyncKeyState(INT nKey
)
566 retval
= (AsyncMouseButtonsStates
[0] ? 0x0001 : 0) |
567 (MouseButtonsStates
[0] ? 0x8000 : 0);
570 retval
= (AsyncMouseButtonsStates
[1] ? 0x0001 : 0) |
571 (MouseButtonsStates
[1] ? 0x8000 : 0);
574 retval
= (AsyncMouseButtonsStates
[2] ? 0x0001 : 0) |
575 (MouseButtonsStates
[2] ? 0x8000 : 0);
578 retval
= AsyncKeyStateTable
[nKey
] |
579 ((InputKeyStateTable
[nKey
] & 0x80) ? 0x8000 : 0);
583 /* all states to false */
584 memset( AsyncMouseButtonsStates
, 0, sizeof(AsyncMouseButtonsStates
) );
585 memset( AsyncKeyStateTable
, 0, sizeof(AsyncKeyStateTable
) );
587 TRACE_(key
)("(%x) -> %x\n", nKey
, retval
);
591 /**********************************************************************
592 * GetAsyncKeyState16 (USER.249)
594 WORD WINAPI
GetAsyncKeyState16(INT16 nKey
)
596 return GetAsyncKeyState(nKey
);
599 /***********************************************************************
600 * IsUserIdle (USER.333)
602 BOOL16 WINAPI
IsUserIdle16(void)
604 if ( GetAsyncKeyState( VK_LBUTTON
) & 0x8000 )
607 if ( GetAsyncKeyState( VK_RBUTTON
) & 0x8000 )
610 if ( GetAsyncKeyState( VK_MBUTTON
) & 0x8000 )
613 /* Should check for screen saver activation here ... */
618 /**********************************************************************
619 * KBD_translate_accelerator
621 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
623 static BOOL
KBD_translate_accelerator(HWND hWnd
,LPMSG msg
,
624 BYTE fVirt
,WORD key
,WORD cmd
)
626 BOOL sendmsg
= FALSE
;
628 if(msg
->wParam
== key
)
630 if (msg
->message
== WM_CHAR
) {
631 if ( !(fVirt
& FALT
) && !(fVirt
& FVIRTKEY
) )
633 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n",
638 if(fVirt
& FVIRTKEY
) {
640 TRACE_(accel
)("found accel for virt_key %04x (scan %04x)\n",
641 msg
->wParam
,0xff & HIWORD(msg
->lParam
));
642 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
643 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
644 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
645 if(mask
== (fVirt
& (FSHIFT
| FCONTROL
| FALT
)))
648 TRACE_(accel
)(", but incorrect SHIFT/CTRL/ALT-state\n");
652 if (!(msg
->lParam
& 0x01000000)) /* no special_key */
654 if ((fVirt
& FALT
) && (msg
->lParam
& 0x20000000))
655 { /* ^^ ALT pressed */
656 TRACE_(accel
)("found accel for Alt-%c\n", msg
->wParam
&0xff);
663 if (sendmsg
) /* found an accelerator, but send a message... ? */
665 INT16 iSysStat
,iStat
,mesg
=0;
668 if (msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
674 if (!IsWindowEnabled(hWnd
))
678 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
680 hMenu
= (wndPtr
->dwStyle
& WS_CHILD
) ? 0 : (HMENU
)wndPtr
->wIDmenu
;
681 iSysStat
= (wndPtr
->hSysMenu
) ? GetMenuState(GetSubMenu16(wndPtr
->hSysMenu
, 0),
682 cmd
, MF_BYCOMMAND
) : -1 ;
683 iStat
= (hMenu
) ? GetMenuState(hMenu
,
684 cmd
, MF_BYCOMMAND
) : -1 ;
686 WIN_ReleaseWndPtr(wndPtr
);
690 if (iSysStat
& (MF_DISABLED
|MF_GRAYED
))
703 if (iStat
& (MF_DISABLED
|MF_GRAYED
))
713 if ( mesg
==WM_COMMAND
|| mesg
==WM_SYSCOMMAND
)
715 TRACE_(accel
)(", sending %s, wParam=%0x\n",
716 mesg
==WM_COMMAND
? "WM_COMMAND" : "WM_SYSCOMMAND",
718 SendMessageA(hWnd
, mesg
, cmd
, 0x00010000L
);
722 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
723 * #0: unknown (please report!)
724 * #1: for WM_KEYUP,WM_SYSKEYUP
725 * #2: mouse is captured
726 * #3: window is disabled
727 * #4: it's a disabled system menu option
728 * #5: it's a menu option, but window is iconic
729 * #6: it's a menu option, but disabled
731 TRACE_(accel
)(", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg
);
733 ERR_(accel
)(" unknown reason - please report!");
741 /**********************************************************************
742 * TranslateAccelerator32 (USER32.551)(USER32.552)(USER32.553)
744 INT WINAPI
TranslateAccelerator(HWND hWnd
, HACCEL hAccel
, LPMSG msg
)
747 LPACCEL16 lpAccelTbl
;
752 WARN_(accel
)("msg null; should hang here to be win compatible\n");
755 if (!hAccel
|| !(lpAccelTbl
= (LPACCEL16
) LockResource16(hAccel
)))
757 WARN_(accel
)("invalid accel handle=%x\n", hAccel
);
760 if ((msg
->message
!= WM_KEYDOWN
&&
761 msg
->message
!= WM_KEYUP
&&
762 msg
->message
!= WM_SYSKEYDOWN
&&
763 msg
->message
!= WM_SYSKEYUP
&&
764 msg
->message
!= WM_CHAR
)) return 0;
766 TRACE_(accel
)("TranslateAccelerators hAccel=%04x, hWnd=%04x,"
767 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%lx\n",
768 hAccel
,hWnd
,msg
->hwnd
,msg
->message
,msg
->wParam
,msg
->lParam
);
773 if (KBD_translate_accelerator(hWnd
,msg
,lpAccelTbl
[i
].fVirt
,
774 lpAccelTbl
[i
].key
,lpAccelTbl
[i
].cmd
))
776 } while ((lpAccelTbl
[i
++].fVirt
& 0x80) == 0);
777 WARN_(accel
)("couldn't translate accelerator key\n");
781 /**********************************************************************
782 * TranslateAccelerator16 (USER.178)
784 INT16 WINAPI
TranslateAccelerator16(HWND16 hWnd
, HACCEL16 hAccel
, LPMSG16 msg
)
786 LPACCEL16 lpAccelTbl
;
792 WARN_(accel
)("msg null; should hang here to be win compatible\n");
795 if (!hAccel
|| !(lpAccelTbl
= (LPACCEL16
) LockResource16(hAccel
)))
797 WARN_(accel
)("invalid accel handle=%x\n", hAccel
);
800 if ((msg
->message
!= WM_KEYDOWN
&&
801 msg
->message
!= WM_KEYUP
&&
802 msg
->message
!= WM_SYSKEYDOWN
&&
803 msg
->message
!= WM_SYSKEYUP
&&
804 msg
->message
!= WM_CHAR
)) return 0;
806 TRACE_(accel
)("TranslateAccelerators hAccel=%04x, hWnd=%04x,\
807 msg->hwnd=%04x, msg->message=%04x, wParam=%04x, lParam=%lx\n", hAccel
,hWnd
,msg
->hwnd
,msg
->message
,msg
->wParam
,msg
->lParam
);
809 STRUCT32_MSG16to32(msg
,&msg32
);
814 if (KBD_translate_accelerator(hWnd
,&msg32
,lpAccelTbl
[i
].fVirt
,
815 lpAccelTbl
[i
].key
,lpAccelTbl
[i
].cmd
))
817 } while ((lpAccelTbl
[i
++].fVirt
& 0x80) == 0);
818 WARN_(accel
)("couldn't translate accelerator key\n");
823 /**********************************************************************
824 * VkKeyScanA (USER32.573)
826 WORD WINAPI
VkKeyScanA(CHAR cChar
)
828 return VkKeyScan16(cChar
);
831 /******************************************************************************
832 * VkKeyScanW (USER32.576)
834 WORD WINAPI
VkKeyScanW(WCHAR cChar
)
836 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
839 /**********************************************************************
840 * VkKeyScanExA (USER32.574)
842 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
844 /* FIXME: complete workaround this is */
845 return VkKeyScan16(cChar
);
848 /******************************************************************************
849 * VkKeyScanExW (USER32.575)
851 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
853 /* FIXME: complete workaround this is */
854 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
857 /******************************************************************************
858 * GetKeyboardType32 (USER32.255)
860 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
862 return GetKeyboardType16(nTypeFlag
);
865 /******************************************************************************
866 * MapVirtualKey32A (USER32.383)
868 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
870 return MapVirtualKey16(code
,maptype
);
873 /******************************************************************************
874 * MapVirtualKey32W (USER32.385)
876 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
878 return MapVirtualKey16(code
,maptype
);
881 /******************************************************************************
882 * MapVirtualKeyEx32A (USER32.384)
884 UINT WINAPI
MapVirtualKeyEx32A(UINT code
, UINT maptype
, HKL hkl
)
887 FIXME_(keyboard
)("(%d,%d,0x%08lx), hkl unhandled!\n",code
,maptype
,(DWORD
)hkl
);
888 return MapVirtualKey16(code
,maptype
);
891 /****************************************************************************
892 * GetKBCodePage32 (USER32.246)
894 UINT WINAPI
GetKBCodePage(void)
896 return GetKBCodePage16();
899 /****************************************************************************
900 * GetKeyboardLayoutName16 (USER.477)
902 INT16 WINAPI
GetKeyboardLayoutName16(LPSTR pwszKLID
)
904 return GetKeyboardLayoutNameA(pwszKLID
);
907 /***********************************************************************
908 * GetKeyboardLayout (USER32.250)
910 * FIXME: - device handle for keyboard layout defaulted to
911 * the language id. This is the way Windows default works.
912 * - the thread identifier (dwLayout) is also ignored.
914 HKL WINAPI
GetKeyboardLayout(DWORD dwLayout
)
917 layout
= GetSystemDefaultLCID(); /* FIXME */
918 layout
|= (layout
<<16); /* FIXME */
919 TRACE_(keyboard
)("returning %08x\n",layout
);
923 /****************************************************************************
924 * GetKeyboardLayoutName32A (USER32.252)
926 INT WINAPI
GetKeyboardLayoutNameA(LPSTR pwszKLID
)
928 sprintf(pwszKLID
, "%08x",GetKeyboardLayout(0));
932 /****************************************************************************
933 * GetKeyboardLayoutName32W (USER32.253)
935 INT WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
937 LPSTR buf
= HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
938 int res
= GetKeyboardLayoutNameA(buf
);
939 lstrcpyAtoW(pwszKLID
,buf
);
940 HeapFree( GetProcessHeap(), 0, buf
);
944 /****************************************************************************
945 * GetKeyNameText32A (USER32.247)
947 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
949 return GetKeyNameText16(lParam
,lpBuffer
,nSize
);
952 /****************************************************************************
953 * GetKeyNameText32W (USER32.248)
955 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
957 LPSTR buf
= HEAP_xalloc( GetProcessHeap(), 0, nSize
);
958 int res
= GetKeyNameTextA(lParam
,buf
,nSize
);
960 lstrcpynAtoW(lpBuffer
,buf
,nSize
);
961 HeapFree( GetProcessHeap(), 0, buf
);
965 /****************************************************************************
966 * ToAscii32 (USER32.546)
968 INT WINAPI
ToAscii( UINT virtKey
,UINT scanCode
,LPBYTE lpKeyState
,
969 LPWORD lpChar
,UINT flags
)
971 return ToAscii16(virtKey
,scanCode
,lpKeyState
,lpChar
,flags
);
974 /****************************************************************************
975 * ToAscii32 (USER32.547)
977 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
978 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
980 /* FIXME: need true implementation */
981 return ToAscii16(virtKey
,scanCode
,lpKeyState
,lpChar
,flags
);
984 /**********************************************************************
985 * ActivateKeyboardLayout32 (USER32.1)
987 * Call ignored. WINE supports only system default keyboard layout.
989 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
991 TRACE_(keyboard
)("(%d, %d)\n", hLayout
, flags
);
992 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
997 /***********************************************************************
998 * GetKeyboardLayoutList (USER32.251)
1000 * FIXME: Supports only the system default language and layout and
1001 * returns only 1 value.
1003 * Return number of values available if either input parm is
1004 * 0, per MS documentation.
1007 INT WINAPI
GetKeyboardLayoutList(INT nBuff
,HKL
*layouts
)
1009 TRACE_(keyboard
)("(%d,%p)\n",nBuff
,layouts
);
1010 if (!nBuff
|| !layouts
)
1013 layouts
[0] = GetKeyboardLayout(0);
1018 /***********************************************************************
1019 * RegisterHotKey (USER32.433)
1021 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
) {
1022 FIXME_(keyboard
)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd
,id
,modifiers
,vk
);
1026 /***********************************************************************
1027 * UnregisterHotKey (USER32.565)
1029 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
) {
1030 FIXME_(keyboard
)("(0x%08x,%d): stub\n",hwnd
,id
);
1035 /***********************************************************************
1036 * ToUnicode32 (USER32.548)
1038 INT WINAPI
ToUnicode(
1046 FIXME_(keyboard
)(": stub\n");
1050 /***********************************************************************
1051 * LoadKeyboardLayout32A (USER32.367)
1052 * Call ignored. WINE supports only system default keyboard layout.
1054 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
1056 TRACE_(keyboard
)("(%s, %d)\n", pwszKLID
, Flags
);
1057 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
1061 /***********************************************************************
1062 * LoadKeyboardLayout32W (USER32.368)
1064 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
1066 LPSTR buf
= HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
1068 lstrcpynWtoA(buf
,pwszKLID
,8);
1070 res
= LoadKeyboardLayoutA(buf
, Flags
);
1071 HeapFree( GetProcessHeap(), 0, buf
);