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"
32 #include "debugtools.h"
37 DECLARE_DEBUG_CHANNEL(accel
);
38 DECLARE_DEBUG_CHANNEL(event
);
39 DECLARE_DEBUG_CHANNEL(key
);
40 DECLARE_DEBUG_CHANNEL(keyboard
);
41 DECLARE_DEBUG_CHANNEL(win
);
43 static BOOL InputEnabled
= TRUE
;
44 BOOL SwappedButtons
= FALSE
;
46 BOOL MouseButtonsStates
[3];
47 BOOL AsyncMouseButtonsStates
[3];
48 BYTE InputKeyStateTable
[256];
49 BYTE QueueKeyStateTable
[256];
50 BYTE AsyncKeyStateTable
[256];
52 /* Storage for the USER-maintained mouse positions */
59 unsigned long count
: 16;
60 unsigned long code
: 8;
61 unsigned long extended
: 1;
62 unsigned long unused
: 2;
63 unsigned long win_internal
: 2;
64 unsigned long context
: 1;
65 unsigned long previous
: 1;
66 unsigned long transition
: 1;
71 /***********************************************************************
72 * keybd_event (USER32.583)
74 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
75 DWORD dwFlags
, DWORD dwExtraInfo
)
82 if (!InputEnabled
) return;
85 * If we are called by the Wine keyboard driver, use the additional
86 * info pointed to by the dwExtraInfo argument.
87 * Otherwise, we need to determine that info ourselves (probably
88 * less accurate, but we can't help that ...).
90 if ( !IsBadReadPtr( (LPVOID
)dwExtraInfo
, sizeof(WINE_KEYBDEVENT
) )
91 && ((WINE_KEYBDEVENT
*)dwExtraInfo
)->magic
== WINE_KEYBDEVENT_MAGIC
)
93 WINE_KEYBDEVENT
*wke
= (WINE_KEYBDEVENT
*)dwExtraInfo
;
99 time
= GetTickCount();
105 keylp
.lp1
.code
= bScan
;
106 keylp
.lp1
.extended
= (dwFlags
& KEYEVENTF_EXTENDEDKEY
) != 0;
107 keylp
.lp1
.win_internal
= 0; /* this has something to do with dialogs,
108 * don't remember where I read it - AK */
109 /* it's '1' under windows, when a dialog box appears
110 * and you press one of the underlined keys - DF*/
112 if ( dwFlags
& KEYEVENTF_KEYUP
)
114 BOOL sysKey
= (InputKeyStateTable
[VK_MENU
] & 0x80)
115 && !(InputKeyStateTable
[VK_CONTROL
] & 0x80)
116 && !(dwFlags
& KEYEVENTF_WINE_FORCEEXTENDED
); /* for Alt from AltGr */
118 InputKeyStateTable
[bVk
] &= ~0x80;
119 keylp
.lp1
.previous
= 1;
120 keylp
.lp1
.transition
= 1;
121 message
= sysKey
? WM_SYSKEYUP
: WM_KEYUP
;
125 keylp
.lp1
.previous
= (InputKeyStateTable
[bVk
] & 0x80) != 0;
126 keylp
.lp1
.transition
= 0;
128 if (!(InputKeyStateTable
[bVk
] & 0x80))
129 InputKeyStateTable
[bVk
] ^= 0x01;
130 InputKeyStateTable
[bVk
] |= 0x80;
132 message
= (InputKeyStateTable
[VK_MENU
] & 0x80)
133 && !(InputKeyStateTable
[VK_CONTROL
] & 0x80)
134 ? WM_SYSKEYDOWN
: WM_KEYDOWN
;
137 if ( message
== WM_SYSKEYDOWN
|| message
== WM_SYSKEYUP
)
138 keylp
.lp1
.context
= (InputKeyStateTable
[VK_MENU
] & 0x80) != 0; /* 1 if alt */
141 TRACE_(key
)(" wParam=%04X, lParam=%08lX\n", bVk
, keylp
.lp2
);
142 TRACE_(key
)(" InputKeyState=%X\n", InputKeyStateTable
[bVk
] );
144 hardware_event( message
, bVk
, keylp
.lp2
, PosX
, PosY
, time
, extra
);
147 /***********************************************************************
148 * WIN16_keybd_event (USER.289)
150 void WINAPI
WIN16_keybd_event( CONTEXT86
*context
)
154 if (AH_reg(context
) & 0x80) dwFlags
|= KEYEVENTF_KEYUP
;
155 if (BH_reg(context
) & 1 ) dwFlags
|= KEYEVENTF_EXTENDEDKEY
;
157 keybd_event( AL_reg(context
), BL_reg(context
),
158 dwFlags
, MAKELONG(SI_reg(context
), DI_reg(context
)) );
161 /***********************************************************************
162 * mouse_event (USER32.584)
164 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
165 DWORD cButtons
, DWORD dwExtraInfo
)
170 if (!InputEnabled
) return;
172 if ( dwFlags
& MOUSEEVENTF_MOVE
)
174 if ( dwFlags
& MOUSEEVENTF_ABSOLUTE
)
176 PosX
= (dx
* GetSystemMetrics(SM_CXSCREEN
)) >> 16;
177 PosY
= (dy
* GetSystemMetrics(SM_CYSCREEN
)) >> 16;
181 int width
= GetSystemMetrics(SM_CXSCREEN
);
182 int height
= GetSystemMetrics(SM_CYSCREEN
);
183 long posX
= (long) PosX
, posY
= (long) PosY
;
185 /* dx and dy can be negative numbers for relative movements */
189 /* Clip to the current screen size */
190 if (posX
< 0) PosX
= 0;
191 else if (posX
>= width
) PosX
= width
- 1;
194 if (posY
< 0) PosY
= 0;
195 else if (posY
>= height
) PosY
= height
- 1;
201 * If we are called by the Wine mouse driver, use the additional
202 * info pointed to by the dwExtraInfo argument.
203 * Otherwise, we need to determine that info ourselves (probably
204 * less accurate, but we can't help that ...).
206 if ( !IsBadReadPtr( (LPVOID
)dwExtraInfo
, sizeof(WINE_MOUSEEVENT
) )
207 && ((WINE_MOUSEEVENT
*)dwExtraInfo
)->magic
== WINE_MOUSEEVENT_MAGIC
)
209 WINE_MOUSEEVENT
*wme
= (WINE_MOUSEEVENT
*)dwExtraInfo
;
211 extra
= (DWORD
)wme
->hWnd
;
212 keyState
= wme
->keyState
;
214 if (keyState
!= GET_KEYSTATE()) {
215 /* We need to update the keystate with what X provides us */
216 MouseButtonsStates
[SwappedButtons
? 2 : 0] = (keyState
& MK_LBUTTON
? TRUE
: FALSE
);
217 MouseButtonsStates
[SwappedButtons
? 0 : 2] = (keyState
& MK_RBUTTON
? TRUE
: FALSE
);
218 MouseButtonsStates
[1] = (keyState
& MK_MBUTTON
? TRUE
: FALSE
);
219 InputKeyStateTable
[VK_SHIFT
] = (keyState
& MK_SHIFT
? 0x80 : 0);
220 InputKeyStateTable
[VK_CONTROL
] = (keyState
& MK_CONTROL
? 0x80 : 0);
225 time
= GetTickCount();
227 keyState
= GET_KEYSTATE();
229 if ( dwFlags
& MOUSEEVENTF_MOVE
)
231 /* We have to actually move the cursor */
232 SetCursorPos( PosX
, PosY
);
237 if ( dwFlags
& MOUSEEVENTF_MOVE
)
239 hardware_event( WM_MOUSEMOVE
,
240 keyState
, 0L, PosX
, PosY
, time
, extra
);
242 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_RIGHTDOWN
) )
244 MouseButtonsStates
[0] = AsyncMouseButtonsStates
[0] = TRUE
;
245 hardware_event( WM_LBUTTONDOWN
,
246 keyState
, 0L, PosX
, PosY
, time
, extra
);
248 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_LEFTUP
: MOUSEEVENTF_RIGHTUP
) )
250 MouseButtonsStates
[0] = FALSE
;
251 hardware_event( WM_LBUTTONUP
,
252 keyState
, 0L, PosX
, PosY
, time
, extra
);
254 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_RIGHTDOWN
: MOUSEEVENTF_LEFTDOWN
) )
256 MouseButtonsStates
[2] = AsyncMouseButtonsStates
[2] = TRUE
;
257 hardware_event( WM_RBUTTONDOWN
,
258 keyState
, 0L, PosX
, PosY
, time
, extra
);
260 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_RIGHTUP
: MOUSEEVENTF_LEFTUP
) )
262 MouseButtonsStates
[2] = FALSE
;
263 hardware_event( WM_RBUTTONUP
,
264 keyState
, 0L, PosX
, PosY
, time
, extra
);
266 if ( dwFlags
& MOUSEEVENTF_MIDDLEDOWN
)
268 MouseButtonsStates
[1] = AsyncMouseButtonsStates
[1] = TRUE
;
269 hardware_event( WM_MBUTTONDOWN
,
270 keyState
, 0L, PosX
, PosY
, time
, extra
);
272 if ( dwFlags
& MOUSEEVENTF_MIDDLEUP
)
274 MouseButtonsStates
[1] = FALSE
;
275 hardware_event( WM_MBUTTONUP
,
276 keyState
, 0L, PosX
, PosY
, time
, extra
);
278 if ( dwFlags
& MOUSEEVENTF_WHEEL
)
280 hardware_event( WM_MOUSEWHEEL
,
281 keyState
, 0L, PosX
, PosY
, time
, extra
);
285 /***********************************************************************
286 * WIN16_mouse_event (USER.299)
288 void WINAPI
WIN16_mouse_event( CONTEXT86
*context
)
290 mouse_event( AX_reg(context
), BX_reg(context
), CX_reg(context
),
291 DX_reg(context
), MAKELONG(SI_reg(context
), DI_reg(context
)) );
294 /***********************************************************************
295 * GetMouseEventProc (USER.337)
297 FARPROC16 WINAPI
GetMouseEventProc16(void)
299 HMODULE16 hmodule
= GetModuleHandle16("USER");
300 return NE_GetEntryPoint( hmodule
, NE_GetOrdinal( hmodule
, "mouse_event" ));
304 /**********************************************************************
305 * EnableHardwareInput (USER.331)
307 BOOL16 WINAPI
EnableHardwareInput16(BOOL16 bEnable
)
309 BOOL16 bOldState
= InputEnabled
;
310 FIXME_(event
)("(%d) - stub\n", bEnable
);
311 InputEnabled
= bEnable
;
316 /***********************************************************************
317 * SwapMouseButton16 (USER.186)
319 BOOL16 WINAPI
SwapMouseButton16( BOOL16 fSwap
)
321 BOOL16 ret
= SwappedButtons
;
322 SwappedButtons
= fSwap
;
327 /***********************************************************************
328 * SwapMouseButton (USER32.537)
330 BOOL WINAPI
SwapMouseButton( BOOL fSwap
)
332 BOOL ret
= SwappedButtons
;
333 SwappedButtons
= fSwap
;
337 /**********************************************************************
340 * We need this to be able to generate double click messages
341 * when menu code captures mouse in the window without CS_DBLCLK style.
343 HWND
EVENT_Capture(HWND hwnd
, INT16 ht
)
345 HWND capturePrev
= 0, captureWnd
= 0;
346 MESSAGEQUEUE
*pMsgQ
= 0, *pCurMsgQ
= 0;
350 /* Get the messageQ for the current thread */
351 if (!(pCurMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
353 WARN_(win
)("\tCurrent message queue not found. Exiting!\n" );
357 /* Get the current capture window from the perQ data of the current message Q */
358 capturePrev
= PERQDATA_GetCaptureWnd( pCurMsgQ
->pQData
);
367 wndPtr
= WIN_FindWndPtr( hwnd
);
370 TRACE_(win
)("(0x%04x)\n", hwnd
);
376 /* Update the perQ capture window and send messages */
377 if( capturePrev
!= captureWnd
)
381 /* Retrieve the message queue associated with this window */
382 pMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( wndPtr
->hmemTaskQ
);
385 WARN_(win
)("\tMessage queue not found. Exiting!\n" );
389 /* Make sure that message queue for the window we are setting capture to
390 * shares the same perQ data as the current threads message queue.
392 if ( pCurMsgQ
->pQData
!= pMsgQ
->pQData
)
396 PERQDATA_SetCaptureWnd( pCurMsgQ
->pQData
, captureWnd
);
397 PERQDATA_SetCaptureInfo( pCurMsgQ
->pQData
, captureHT
);
401 WND
* wndPtr
= WIN_FindWndPtr( capturePrev
);
402 if( wndPtr
&& (wndPtr
->flags
& WIN_ISWIN32
) )
403 SendMessageA( capturePrev
, WM_CAPTURECHANGED
, 0L, hwnd
);
404 WIN_ReleaseWndPtr(wndPtr
);
409 /* Unlock the queues before returning */
411 QUEUE_Unlock( pMsgQ
);
413 QUEUE_Unlock( pCurMsgQ
);
415 WIN_ReleaseWndPtr(wndPtr
);
420 /**********************************************************************
421 * SetCapture16 (USER.18)
423 HWND16 WINAPI
SetCapture16( HWND16 hwnd
)
425 return (HWND16
)EVENT_Capture( hwnd
, HTCLIENT
);
429 /**********************************************************************
430 * SetCapture (USER32.464)
432 HWND WINAPI
SetCapture( HWND hwnd
)
434 return EVENT_Capture( hwnd
, HTCLIENT
);
438 /**********************************************************************
439 * ReleaseCapture (USER.19) (USER32.439)
441 BOOL WINAPI
ReleaseCapture(void)
443 return (EVENT_Capture( 0, 0 ) != 0);
447 /**********************************************************************
448 * GetCapture16 (USER.236)
450 HWND16 WINAPI
GetCapture16(void)
452 return (HWND16
)GetCapture();
455 /**********************************************************************
456 * GetCapture (USER32.208)
458 HWND WINAPI
GetCapture(void)
460 MESSAGEQUEUE
*pCurMsgQ
= 0;
461 HWND hwndCapture
= 0;
463 /* Get the messageQ for the current thread */
464 if (!(pCurMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
466 TRACE_(win
)("GetCapture32: Current message queue not found. Exiting!\n" );
470 /* Get the current capture window from the perQ data of the current message Q */
471 hwndCapture
= PERQDATA_GetCaptureWnd( pCurMsgQ
->pQData
);
473 QUEUE_Unlock( pCurMsgQ
);
477 /**********************************************************************
478 * GetKeyState (USER.106)
480 INT16 WINAPI
GetKeyState16(INT16 vkey
)
482 return GetKeyState(vkey
);
485 /**********************************************************************
486 * GetKeyState (USER32.249)
488 * An application calls the GetKeyState function in response to a
489 * keyboard-input message. This function retrieves the state of the key
490 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
492 SHORT WINAPI
GetKeyState(INT vkey
)
498 case VK_LBUTTON
: /* VK_LBUTTON is 1 */
499 retval
= MouseButtonsStates
[0] ? 0x8000 : 0;
501 case VK_MBUTTON
: /* VK_MBUTTON is 4 */
502 retval
= MouseButtonsStates
[1] ? 0x8000 : 0;
504 case VK_RBUTTON
: /* VK_RBUTTON is 2 */
505 retval
= MouseButtonsStates
[2] ? 0x8000 : 0;
508 if (vkey
>= 'a' && vkey
<= 'z')
510 retval
= ( (WORD
)(QueueKeyStateTable
[vkey
] & 0x80) << 8 ) |
511 (WORD
)(QueueKeyStateTable
[vkey
] & 0x01);
513 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
517 /**********************************************************************
518 * GetKeyboardState (USER.222)(USER32.254)
520 * An application calls the GetKeyboardState function in response to a
521 * keyboard-input message. This function retrieves the state of the keyboard
522 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
524 BOOL WINAPI
GetKeyboardState(LPBYTE lpKeyState
)
526 TRACE_(key
)("(%p)\n", lpKeyState
);
527 if (lpKeyState
!= NULL
) {
528 QueueKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] ? 0x80 : 0;
529 QueueKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] ? 0x80 : 0;
530 QueueKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] ? 0x80 : 0;
531 memcpy(lpKeyState
, QueueKeyStateTable
, 256);
537 /**********************************************************************
538 * SetKeyboardState (USER.223)(USER32.484)
540 BOOL WINAPI
SetKeyboardState(LPBYTE lpKeyState
)
542 TRACE_(key
)("(%p)\n", lpKeyState
);
543 if (lpKeyState
!= NULL
) {
544 memcpy(QueueKeyStateTable
, lpKeyState
, 256);
545 MouseButtonsStates
[0] = (QueueKeyStateTable
[VK_LBUTTON
] != 0);
546 MouseButtonsStates
[1] = (QueueKeyStateTable
[VK_MBUTTON
] != 0);
547 MouseButtonsStates
[2] = (QueueKeyStateTable
[VK_RBUTTON
] != 0);
553 /**********************************************************************
554 * GetAsyncKeyState (USER32.207)
556 * Determine if a key is or was pressed. retval has high-order
557 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
560 * This uses the variable AsyncMouseButtonsStates and
561 * AsyncKeyStateTable (set in event.c) which have the mouse button
562 * number or key number (whichever is applicable) set to true if the
563 * mouse or key had been depressed since the last call to
566 WORD WINAPI
GetAsyncKeyState(INT nKey
)
572 retval
= (AsyncMouseButtonsStates
[0] ? 0x0001 : 0) |
573 (MouseButtonsStates
[0] ? 0x8000 : 0);
576 retval
= (AsyncMouseButtonsStates
[1] ? 0x0001 : 0) |
577 (MouseButtonsStates
[1] ? 0x8000 : 0);
580 retval
= (AsyncMouseButtonsStates
[2] ? 0x0001 : 0) |
581 (MouseButtonsStates
[2] ? 0x8000 : 0);
584 retval
= AsyncKeyStateTable
[nKey
] |
585 ((InputKeyStateTable
[nKey
] & 0x80) ? 0x8000 : 0);
589 /* all states to false */
590 memset( AsyncMouseButtonsStates
, 0, sizeof(AsyncMouseButtonsStates
) );
591 memset( AsyncKeyStateTable
, 0, sizeof(AsyncKeyStateTable
) );
593 TRACE_(key
)("(%x) -> %x\n", nKey
, retval
);
597 /**********************************************************************
598 * GetAsyncKeyState16 (USER.249)
600 WORD WINAPI
GetAsyncKeyState16(INT16 nKey
)
602 return GetAsyncKeyState(nKey
);
605 /***********************************************************************
606 * IsUserIdle (USER.333)
608 BOOL16 WINAPI
IsUserIdle16(void)
610 if ( GetAsyncKeyState( VK_LBUTTON
) & 0x8000 )
613 if ( GetAsyncKeyState( VK_RBUTTON
) & 0x8000 )
616 if ( GetAsyncKeyState( VK_MBUTTON
) & 0x8000 )
619 /* Should check for screen saver activation here ... */
624 /**********************************************************************
625 * KBD_translate_accelerator
627 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
629 static BOOL
KBD_translate_accelerator(HWND hWnd
,LPMSG msg
,
630 BYTE fVirt
,WORD key
,WORD cmd
)
632 BOOL sendmsg
= FALSE
;
634 if(msg
->wParam
== key
)
636 if (msg
->message
== WM_CHAR
) {
637 if ( !(fVirt
& FALT
) && !(fVirt
& FVIRTKEY
) )
639 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n",
644 if(fVirt
& FVIRTKEY
) {
646 TRACE_(accel
)("found accel for virt_key %04x (scan %04x)\n",
647 msg
->wParam
,0xff & HIWORD(msg
->lParam
));
648 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
649 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
650 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
651 if(mask
== (fVirt
& (FSHIFT
| FCONTROL
| FALT
)))
654 TRACE_(accel
)(", but incorrect SHIFT/CTRL/ALT-state\n");
658 if (!(msg
->lParam
& 0x01000000)) /* no special_key */
660 if ((fVirt
& FALT
) && (msg
->lParam
& 0x20000000))
661 { /* ^^ ALT pressed */
662 TRACE_(accel
)("found accel for Alt-%c\n", msg
->wParam
&0xff);
669 if (sendmsg
) /* found an accelerator, but send a message... ? */
671 INT16 iSysStat
,iStat
,mesg
=0;
674 if (msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
680 if (!IsWindowEnabled(hWnd
))
684 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
686 hMenu
= (wndPtr
->dwStyle
& WS_CHILD
) ? 0 : (HMENU
)wndPtr
->wIDmenu
;
687 iSysStat
= (wndPtr
->hSysMenu
) ? GetMenuState(GetSubMenu16(wndPtr
->hSysMenu
, 0),
688 cmd
, MF_BYCOMMAND
) : -1 ;
689 iStat
= (hMenu
) ? GetMenuState(hMenu
,
690 cmd
, MF_BYCOMMAND
) : -1 ;
692 WIN_ReleaseWndPtr(wndPtr
);
696 if (iSysStat
& (MF_DISABLED
|MF_GRAYED
))
709 if (iStat
& (MF_DISABLED
|MF_GRAYED
))
719 if( mesg
==WM_COMMAND
) {
720 TRACE_(accel
)(", sending WM_COMMAND, wParam=%0x\n", 0x10000 | cmd
);
721 SendMessageA(hWnd
, mesg
, 0x10000 | cmd
, 0L);
722 } else if( mesg
==WM_SYSCOMMAND
) {
723 TRACE_(accel
)(", sending WM_SYSCOMMAND, wParam=%0x\n", cmd
);
724 SendMessageA(hWnd
, mesg
, cmd
, 0x00010000L
);
728 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
729 * #0: unknown (please report!)
730 * #1: for WM_KEYUP,WM_SYSKEYUP
731 * #2: mouse is captured
732 * #3: window is disabled
733 * #4: it's a disabled system menu option
734 * #5: it's a menu option, but window is iconic
735 * #6: it's a menu option, but disabled
737 TRACE_(accel
)(", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg
);
739 ERR_(accel
)(" unknown reason - please report!");
747 /**********************************************************************
748 * TranslateAccelerator (USER32.551)(USER32.552)(USER32.553)
750 INT WINAPI
TranslateAccelerator(HWND hWnd
, HACCEL hAccel
, LPMSG msg
)
753 LPACCEL16 lpAccelTbl
;
758 WARN_(accel
)("msg null; should hang here to be win compatible\n");
761 if (!hAccel
|| !(lpAccelTbl
= (LPACCEL16
) LockResource16(hAccel
)))
763 WARN_(accel
)("invalid accel handle=%x\n", hAccel
);
766 if ((msg
->message
!= WM_KEYDOWN
&&
767 msg
->message
!= WM_KEYUP
&&
768 msg
->message
!= WM_SYSKEYDOWN
&&
769 msg
->message
!= WM_SYSKEYUP
&&
770 msg
->message
!= WM_CHAR
)) return 0;
772 TRACE_(accel
)("TranslateAccelerators hAccel=%04x, hWnd=%04x,"
773 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%lx\n",
774 hAccel
,hWnd
,msg
->hwnd
,msg
->message
,msg
->wParam
,msg
->lParam
);
779 if (KBD_translate_accelerator(hWnd
,msg
,lpAccelTbl
[i
].fVirt
,
780 lpAccelTbl
[i
].key
,lpAccelTbl
[i
].cmd
))
782 } while ((lpAccelTbl
[i
++].fVirt
& 0x80) == 0);
783 WARN_(accel
)("couldn't translate accelerator key\n");
787 /**********************************************************************
788 * TranslateAccelerator16 (USER.178)
790 INT16 WINAPI
TranslateAccelerator16(HWND16 hWnd
, HACCEL16 hAccel
, LPMSG16 msg
)
792 LPACCEL16 lpAccelTbl
;
798 WARN_(accel
)("msg null; should hang here to be win compatible\n");
801 if (!hAccel
|| !(lpAccelTbl
= (LPACCEL16
) LockResource16(hAccel
)))
803 WARN_(accel
)("invalid accel handle=%x\n", hAccel
);
806 if ((msg
->message
!= WM_KEYDOWN
&&
807 msg
->message
!= WM_KEYUP
&&
808 msg
->message
!= WM_SYSKEYDOWN
&&
809 msg
->message
!= WM_SYSKEYUP
&&
810 msg
->message
!= WM_CHAR
)) return 0;
812 TRACE_(accel
)("TranslateAccelerators hAccel=%04x, hWnd=%04x,\
813 msg->hwnd=%04x, msg->message=%04x, wParam=%04x, lParam=%lx\n", hAccel
,hWnd
,msg
->hwnd
,msg
->message
,msg
->wParam
,msg
->lParam
);
815 STRUCT32_MSG16to32(msg
,&msg32
);
820 if (KBD_translate_accelerator(hWnd
,&msg32
,lpAccelTbl
[i
].fVirt
,
821 lpAccelTbl
[i
].key
,lpAccelTbl
[i
].cmd
))
823 } while ((lpAccelTbl
[i
++].fVirt
& 0x80) == 0);
824 WARN_(accel
)("couldn't translate accelerator key\n");
829 /**********************************************************************
830 * VkKeyScanA (USER32.573)
832 WORD WINAPI
VkKeyScanA(CHAR cChar
)
834 return VkKeyScan16(cChar
);
837 /******************************************************************************
838 * VkKeyScanW (USER32.576)
840 WORD WINAPI
VkKeyScanW(WCHAR cChar
)
842 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
845 /**********************************************************************
846 * VkKeyScanExA (USER32.574)
848 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
850 /* FIXME: complete workaround this is */
851 return VkKeyScan16(cChar
);
854 /******************************************************************************
855 * VkKeyScanExW (USER32.575)
857 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
859 /* FIXME: complete workaround this is */
860 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
863 /******************************************************************************
864 * GetKeyboardType (USER32.255)
866 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
868 return GetKeyboardType16(nTypeFlag
);
871 /******************************************************************************
872 * MapVirtualKeyA (USER32.383)
874 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
876 return MapVirtualKey16(code
,maptype
);
879 /******************************************************************************
880 * MapVirtualKeyW (USER32.385)
882 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
884 return MapVirtualKey16(code
,maptype
);
887 /******************************************************************************
888 * MapVirtualKeyExA (USER32.384)
890 UINT WINAPI
MapVirtualKeyExA(UINT code
, UINT maptype
, HKL hkl
)
893 FIXME_(keyboard
)("(%d,%d,0x%08lx), hkl unhandled!\n",code
,maptype
,(DWORD
)hkl
);
894 return MapVirtualKey16(code
,maptype
);
897 /****************************************************************************
898 * GetKBCodePage (USER32.246)
900 UINT WINAPI
GetKBCodePage(void)
902 return GetKBCodePage16();
905 /****************************************************************************
906 * GetKeyboardLayoutName16 (USER.477)
908 INT16 WINAPI
GetKeyboardLayoutName16(LPSTR pwszKLID
)
910 return GetKeyboardLayoutNameA(pwszKLID
);
913 /***********************************************************************
914 * GetKeyboardLayout (USER32.250)
916 * FIXME: - device handle for keyboard layout defaulted to
917 * the language id. This is the way Windows default works.
918 * - the thread identifier (dwLayout) is also ignored.
920 HKL WINAPI
GetKeyboardLayout(DWORD dwLayout
)
923 layout
= GetSystemDefaultLCID(); /* FIXME */
924 layout
|= (layout
<<16); /* FIXME */
925 TRACE_(keyboard
)("returning %08x\n",layout
);
929 /****************************************************************************
930 * GetKeyboardLayoutNameA (USER32.252)
932 INT WINAPI
GetKeyboardLayoutNameA(LPSTR pwszKLID
)
934 sprintf(pwszKLID
, "%08x",GetKeyboardLayout(0));
938 /****************************************************************************
939 * GetKeyboardLayoutNameW (USER32.253)
941 INT WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
944 int res
= GetKeyboardLayoutNameA(buf
);
945 lstrcpyAtoW(pwszKLID
,buf
);
949 /****************************************************************************
950 * GetKeyNameTextA (USER32.247)
952 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
954 return GetKeyNameText16(lParam
,lpBuffer
,nSize
);
957 /****************************************************************************
958 * GetKeyNameTextW (USER32.248)
960 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
963 LPSTR buf
= HeapAlloc( GetProcessHeap(), 0, nSize
);
964 if(buf
== NULL
) return 0; /* FIXME: is this the correct failure value?*/
965 res
= GetKeyNameTextA(lParam
,buf
,nSize
);
967 lstrcpynAtoW(lpBuffer
,buf
,nSize
);
968 HeapFree( GetProcessHeap(), 0, buf
);
972 /****************************************************************************
973 * ToAscii (USER32.546)
975 INT WINAPI
ToAscii( UINT virtKey
,UINT scanCode
,LPBYTE lpKeyState
,
976 LPWORD lpChar
,UINT flags
)
978 return ToAscii16(virtKey
,scanCode
,lpKeyState
,lpChar
,flags
);
981 /****************************************************************************
982 * ToAsciiEx (USER32.547)
984 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
985 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
987 /* FIXME: need true implementation */
988 return ToAscii16(virtKey
,scanCode
,lpKeyState
,lpChar
,flags
);
991 /**********************************************************************
992 * ActivateKeyboardLayout (USER32.1)
994 * Call ignored. WINE supports only system default keyboard layout.
996 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
998 TRACE_(keyboard
)("(%d, %d)\n", hLayout
, flags
);
999 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
1004 /***********************************************************************
1005 * GetKeyboardLayoutList (USER32.251)
1007 * FIXME: Supports only the system default language and layout and
1008 * returns only 1 value.
1010 * Return number of values available if either input parm is
1011 * 0, per MS documentation.
1014 INT WINAPI
GetKeyboardLayoutList(INT nBuff
,HKL
*layouts
)
1016 TRACE_(keyboard
)("(%d,%p)\n",nBuff
,layouts
);
1017 if (!nBuff
|| !layouts
)
1020 layouts
[0] = GetKeyboardLayout(0);
1025 /***********************************************************************
1026 * RegisterHotKey (USER32.433)
1028 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
) {
1029 FIXME_(keyboard
)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd
,id
,modifiers
,vk
);
1033 /***********************************************************************
1034 * UnregisterHotKey (USER32.565)
1036 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
) {
1037 FIXME_(keyboard
)("(0x%08x,%d): stub\n",hwnd
,id
);
1042 /***********************************************************************
1043 * ToUnicode (USER32.548)
1045 INT WINAPI
ToUnicode(
1053 FIXME_(keyboard
)(": stub\n");
1057 /***********************************************************************
1058 * LoadKeyboardLayoutA (USER32.367)
1059 * Call ignored. WINE supports only system default keyboard layout.
1061 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
1063 TRACE_(keyboard
)("(%s, %d)\n", pwszKLID
, Flags
);
1064 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
1068 /***********************************************************************
1069 * LoadKeyboardLayoutW (USER32.368)
1071 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
1075 lstrcpynWtoA(buf
,pwszKLID
,8);
1077 return LoadKeyboardLayoutA(buf
, Flags
);