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/winestring.h"
24 #include "wine/keyboard16.h"
33 #include "debugtools.h"
38 DECLARE_DEBUG_CHANNEL(accel
);
39 DECLARE_DEBUG_CHANNEL(event
);
40 DECLARE_DEBUG_CHANNEL(key
);
41 DECLARE_DEBUG_CHANNEL(keyboard
);
42 DECLARE_DEBUG_CHANNEL(win
);
44 static BOOL InputEnabled
= TRUE
;
45 BOOL SwappedButtons
= FALSE
;
47 BOOL MouseButtonsStates
[3];
48 BOOL AsyncMouseButtonsStates
[3];
49 BYTE InputKeyStateTable
[256];
50 BYTE QueueKeyStateTable
[256];
51 BYTE AsyncKeyStateTable
[256];
53 /* Storage for the USER-maintained mouse positions */
60 unsigned long count
: 16;
61 unsigned long code
: 8;
62 unsigned long extended
: 1;
63 unsigned long unused
: 2;
64 unsigned long win_internal
: 2;
65 unsigned long context
: 1;
66 unsigned long previous
: 1;
67 unsigned long transition
: 1;
72 /***********************************************************************
73 * keybd_event (USER32.583)
75 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
76 DWORD dwFlags
, DWORD dwExtraInfo
)
83 if (!InputEnabled
) return;
86 * If we are called by the Wine keyboard driver, use the additional
87 * info pointed to by the dwExtraInfo argument.
88 * Otherwise, we need to determine that info ourselves (probably
89 * less accurate, but we can't help that ...).
91 if ( !IsBadReadPtr( (LPVOID
)dwExtraInfo
, sizeof(WINE_KEYBDEVENT
) )
92 && ((WINE_KEYBDEVENT
*)dwExtraInfo
)->magic
== WINE_KEYBDEVENT_MAGIC
)
94 WINE_KEYBDEVENT
*wke
= (WINE_KEYBDEVENT
*)dwExtraInfo
;
100 time
= GetTickCount();
106 keylp
.lp1
.code
= bScan
;
107 keylp
.lp1
.extended
= (dwFlags
& KEYEVENTF_EXTENDEDKEY
) != 0;
108 keylp
.lp1
.win_internal
= 0; /* this has something to do with dialogs,
109 * don't remember where I read it - AK */
110 /* it's '1' under windows, when a dialog box appears
111 * and you press one of the underlined keys - DF*/
113 if ( dwFlags
& KEYEVENTF_KEYUP
)
115 BOOL sysKey
= (InputKeyStateTable
[VK_MENU
] & 0x80)
116 && !(InputKeyStateTable
[VK_CONTROL
] & 0x80)
117 && !(dwFlags
& KEYEVENTF_WINE_FORCEEXTENDED
); /* for Alt from AltGr */
119 InputKeyStateTable
[bVk
] &= ~0x80;
120 keylp
.lp1
.previous
= 1;
121 keylp
.lp1
.transition
= 1;
122 message
= sysKey
? WM_SYSKEYUP
: WM_KEYUP
;
126 keylp
.lp1
.previous
= (InputKeyStateTable
[bVk
] & 0x80) != 0;
127 keylp
.lp1
.transition
= 0;
129 if (!(InputKeyStateTable
[bVk
] & 0x80))
130 InputKeyStateTable
[bVk
] ^= 0x01;
131 InputKeyStateTable
[bVk
] |= 0x80;
133 message
= (InputKeyStateTable
[VK_MENU
] & 0x80)
134 && !(InputKeyStateTable
[VK_CONTROL
] & 0x80)
135 ? WM_SYSKEYDOWN
: WM_KEYDOWN
;
138 if ( message
== WM_SYSKEYDOWN
|| message
== WM_SYSKEYUP
)
139 keylp
.lp1
.context
= (InputKeyStateTable
[VK_MENU
] & 0x80) != 0; /* 1 if alt */
142 TRACE_(key
)(" wParam=%04X, lParam=%08lX\n", bVk
, keylp
.lp2
);
143 TRACE_(key
)(" InputKeyState=%X\n", InputKeyStateTable
[bVk
] );
145 hardware_event( message
, bVk
, keylp
.lp2
, PosX
, PosY
, time
, extra
);
148 /***********************************************************************
149 * WIN16_keybd_event (USER.289)
151 void WINAPI
WIN16_keybd_event( CONTEXT86
*context
)
155 if (AH_reg(context
) & 0x80) dwFlags
|= KEYEVENTF_KEYUP
;
156 if (BH_reg(context
) & 1 ) dwFlags
|= KEYEVENTF_EXTENDEDKEY
;
158 keybd_event( AL_reg(context
), BL_reg(context
),
159 dwFlags
, MAKELONG(SI_reg(context
), DI_reg(context
)) );
162 /***********************************************************************
163 * mouse_event (USER32.584)
165 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
166 DWORD cButtons
, DWORD dwExtraInfo
)
171 if (!InputEnabled
) return;
173 if ( dwFlags
& MOUSEEVENTF_MOVE
)
175 if ( dwFlags
& MOUSEEVENTF_ABSOLUTE
)
177 PosX
= (dx
* GetSystemMetrics(SM_CXSCREEN
)) >> 16;
178 PosY
= (dy
* GetSystemMetrics(SM_CYSCREEN
)) >> 16;
182 int width
= GetSystemMetrics(SM_CXSCREEN
);
183 int height
= GetSystemMetrics(SM_CYSCREEN
);
184 long posX
= (long) PosX
, posY
= (long) PosY
;
186 /* dx and dy can be negative numbers for relative movements */
190 /* Clip to the current screen size */
191 if (posX
< 0) PosX
= 0;
192 else if (posX
>= width
) PosX
= width
- 1;
195 if (posY
< 0) PosY
= 0;
196 else if (posY
>= height
) PosY
= height
- 1;
202 * If we are called by the Wine mouse driver, use the additional
203 * info pointed to by the dwExtraInfo argument.
204 * Otherwise, we need to determine that info ourselves (probably
205 * less accurate, but we can't help that ...).
207 if ( !IsBadReadPtr( (LPVOID
)dwExtraInfo
, sizeof(WINE_MOUSEEVENT
) )
208 && ((WINE_MOUSEEVENT
*)dwExtraInfo
)->magic
== WINE_MOUSEEVENT_MAGIC
)
210 WINE_MOUSEEVENT
*wme
= (WINE_MOUSEEVENT
*)dwExtraInfo
;
212 extra
= (DWORD
)wme
->hWnd
;
213 keyState
= wme
->keyState
;
215 if (keyState
!= GET_KEYSTATE()) {
216 /* We need to update the keystate with what X provides us */
217 MouseButtonsStates
[SwappedButtons
? 2 : 0] = (keyState
& MK_LBUTTON
? TRUE
: FALSE
);
218 MouseButtonsStates
[SwappedButtons
? 0 : 2] = (keyState
& MK_RBUTTON
? TRUE
: FALSE
);
219 MouseButtonsStates
[1] = (keyState
& MK_MBUTTON
? TRUE
: FALSE
);
220 InputKeyStateTable
[VK_SHIFT
] = (keyState
& MK_SHIFT
? 0x80 : 0);
221 InputKeyStateTable
[VK_CONTROL
] = (keyState
& MK_CONTROL
? 0x80 : 0);
226 time
= GetTickCount();
228 keyState
= GET_KEYSTATE();
230 if ( dwFlags
& MOUSEEVENTF_MOVE
)
232 /* We have to actually move the cursor */
233 SetCursorPos( PosX
, PosY
);
238 if ( dwFlags
& MOUSEEVENTF_MOVE
)
240 hardware_event( WM_MOUSEMOVE
,
241 keyState
, 0L, PosX
, PosY
, time
, extra
);
243 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_RIGHTDOWN
) )
245 MouseButtonsStates
[0] = AsyncMouseButtonsStates
[0] = TRUE
;
246 hardware_event( WM_LBUTTONDOWN
,
247 keyState
, 0L, PosX
, PosY
, time
, extra
);
249 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_LEFTUP
: MOUSEEVENTF_RIGHTUP
) )
251 MouseButtonsStates
[0] = FALSE
;
252 hardware_event( WM_LBUTTONUP
,
253 keyState
, 0L, PosX
, PosY
, time
, extra
);
255 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_RIGHTDOWN
: MOUSEEVENTF_LEFTDOWN
) )
257 MouseButtonsStates
[2] = AsyncMouseButtonsStates
[2] = TRUE
;
258 hardware_event( WM_RBUTTONDOWN
,
259 keyState
, 0L, PosX
, PosY
, time
, extra
);
261 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_RIGHTUP
: MOUSEEVENTF_LEFTUP
) )
263 MouseButtonsStates
[2] = FALSE
;
264 hardware_event( WM_RBUTTONUP
,
265 keyState
, 0L, PosX
, PosY
, time
, extra
);
267 if ( dwFlags
& MOUSEEVENTF_MIDDLEDOWN
)
269 MouseButtonsStates
[1] = AsyncMouseButtonsStates
[1] = TRUE
;
270 hardware_event( WM_MBUTTONDOWN
,
271 keyState
, 0L, PosX
, PosY
, time
, extra
);
273 if ( dwFlags
& MOUSEEVENTF_MIDDLEUP
)
275 MouseButtonsStates
[1] = FALSE
;
276 hardware_event( WM_MBUTTONUP
,
277 keyState
, 0L, PosX
, PosY
, time
, extra
);
279 if ( dwFlags
& MOUSEEVENTF_WHEEL
)
281 hardware_event( WM_MOUSEWHEEL
,
282 keyState
, 0L, PosX
, PosY
, time
, extra
);
286 /***********************************************************************
287 * WIN16_mouse_event (USER.299)
289 void WINAPI
WIN16_mouse_event( CONTEXT86
*context
)
291 mouse_event( AX_reg(context
), BX_reg(context
), CX_reg(context
),
292 DX_reg(context
), MAKELONG(SI_reg(context
), DI_reg(context
)) );
295 /***********************************************************************
296 * GetMouseEventProc (USER.337)
298 FARPROC16 WINAPI
GetMouseEventProc16(void)
300 HMODULE16 hmodule
= GetModuleHandle16("USER");
301 return NE_GetEntryPoint( hmodule
, NE_GetOrdinal( hmodule
, "mouse_event" ));
305 /**********************************************************************
306 * EnableHardwareInput (USER.331)
308 BOOL16 WINAPI
EnableHardwareInput16(BOOL16 bEnable
)
310 BOOL16 bOldState
= InputEnabled
;
311 FIXME_(event
)("(%d) - stub\n", bEnable
);
312 InputEnabled
= bEnable
;
317 /***********************************************************************
318 * SwapMouseButton16 (USER.186)
320 BOOL16 WINAPI
SwapMouseButton16( BOOL16 fSwap
)
322 BOOL16 ret
= SwappedButtons
;
323 SwappedButtons
= fSwap
;
328 /***********************************************************************
329 * SwapMouseButton (USER32.537)
331 BOOL WINAPI
SwapMouseButton( BOOL fSwap
)
333 BOOL ret
= SwappedButtons
;
334 SwappedButtons
= fSwap
;
338 /**********************************************************************
341 * We need this to be able to generate double click messages
342 * when menu code captures mouse in the window without CS_DBLCLK style.
344 HWND
EVENT_Capture(HWND hwnd
, INT16 ht
)
346 HWND capturePrev
= 0, captureWnd
= 0;
347 MESSAGEQUEUE
*pMsgQ
= 0, *pCurMsgQ
= 0;
351 /* Get the messageQ for the current thread */
352 if (!(pCurMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
354 WARN_(win
)("\tCurrent message queue not found. Exiting!\n" );
358 /* Get the current capture window from the perQ data of the current message Q */
359 capturePrev
= PERQDATA_GetCaptureWnd( pCurMsgQ
->pQData
);
368 wndPtr
= WIN_FindWndPtr( hwnd
);
371 TRACE_(win
)("(0x%04x)\n", hwnd
);
377 /* Update the perQ capture window and send messages */
378 if( capturePrev
!= captureWnd
)
382 /* Retrieve the message queue associated with this window */
383 pMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( wndPtr
->hmemTaskQ
);
386 WARN_(win
)("\tMessage queue not found. Exiting!\n" );
390 /* Make sure that message queue for the window we are setting capture to
391 * shares the same perQ data as the current threads message queue.
393 if ( pCurMsgQ
->pQData
!= pMsgQ
->pQData
)
397 PERQDATA_SetCaptureWnd( pCurMsgQ
->pQData
, captureWnd
);
398 PERQDATA_SetCaptureInfo( pCurMsgQ
->pQData
, captureHT
);
402 WND
* xwndPtr
= WIN_FindWndPtr( capturePrev
);
403 if( xwndPtr
&& (xwndPtr
->flags
& WIN_ISWIN32
) )
404 SendMessageA( capturePrev
, WM_CAPTURECHANGED
, 0L, hwnd
);
405 WIN_ReleaseWndPtr(xwndPtr
);
410 /* Unlock the queues before returning */
412 QUEUE_Unlock( pMsgQ
);
414 QUEUE_Unlock( pCurMsgQ
);
416 WIN_ReleaseWndPtr(wndPtr
);
421 /**********************************************************************
422 * SetCapture16 (USER.18)
424 HWND16 WINAPI
SetCapture16( HWND16 hwnd
)
426 return (HWND16
)EVENT_Capture( hwnd
, HTCLIENT
);
430 /**********************************************************************
431 * SetCapture (USER32.464)
433 HWND WINAPI
SetCapture( HWND hwnd
)
435 return EVENT_Capture( hwnd
, HTCLIENT
);
439 /**********************************************************************
440 * ReleaseCapture (USER.19) (USER32.439)
442 BOOL WINAPI
ReleaseCapture(void)
444 return (EVENT_Capture( 0, 0 ) != 0);
448 /**********************************************************************
449 * GetCapture16 (USER.236)
451 HWND16 WINAPI
GetCapture16(void)
453 return (HWND16
)GetCapture();
456 /**********************************************************************
457 * GetCapture (USER32.208)
459 HWND WINAPI
GetCapture(void)
461 MESSAGEQUEUE
*pCurMsgQ
= 0;
462 HWND hwndCapture
= 0;
464 /* Get the messageQ for the current thread */
465 if (!(pCurMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
467 TRACE_(win
)("GetCapture: Current message queue not found. Exiting!\n" );
471 /* Get the current capture window from the perQ data of the current message Q */
472 hwndCapture
= PERQDATA_GetCaptureWnd( pCurMsgQ
->pQData
);
474 QUEUE_Unlock( pCurMsgQ
);
478 /**********************************************************************
479 * GetKeyState (USER.106)
481 INT16 WINAPI
GetKeyState16(INT16 vkey
)
483 return GetKeyState(vkey
);
486 /**********************************************************************
487 * GetKeyState (USER32.249)
489 * An application calls the GetKeyState function in response to a
490 * keyboard-input message. This function retrieves the state of the key
491 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
493 SHORT WINAPI
GetKeyState(INT vkey
)
499 case VK_LBUTTON
: /* VK_LBUTTON is 1 */
500 retval
= MouseButtonsStates
[0] ? 0x8000 : 0;
502 case VK_MBUTTON
: /* VK_MBUTTON is 4 */
503 retval
= MouseButtonsStates
[1] ? 0x8000 : 0;
505 case VK_RBUTTON
: /* VK_RBUTTON is 2 */
506 retval
= MouseButtonsStates
[2] ? 0x8000 : 0;
509 if (vkey
>= 'a' && vkey
<= 'z')
511 retval
= ( (WORD
)(QueueKeyStateTable
[vkey
] & 0x80) << 8 ) |
512 (WORD
)(QueueKeyStateTable
[vkey
] & 0x01);
514 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
518 /**********************************************************************
519 * GetKeyboardState (USER.222)(USER32.254)
521 * An application calls the GetKeyboardState function in response to a
522 * keyboard-input message. This function retrieves the state of the keyboard
523 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
525 BOOL WINAPI
GetKeyboardState(LPBYTE lpKeyState
)
527 TRACE_(key
)("(%p)\n", lpKeyState
);
528 if (lpKeyState
!= NULL
) {
529 QueueKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] ? 0x80 : 0;
530 QueueKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] ? 0x80 : 0;
531 QueueKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] ? 0x80 : 0;
532 memcpy(lpKeyState
, QueueKeyStateTable
, 256);
538 /**********************************************************************
539 * SetKeyboardState (USER.223)(USER32.484)
541 BOOL WINAPI
SetKeyboardState(LPBYTE lpKeyState
)
543 TRACE_(key
)("(%p)\n", lpKeyState
);
544 if (lpKeyState
!= NULL
) {
545 memcpy(QueueKeyStateTable
, lpKeyState
, 256);
546 MouseButtonsStates
[0] = (QueueKeyStateTable
[VK_LBUTTON
] != 0);
547 MouseButtonsStates
[1] = (QueueKeyStateTable
[VK_MBUTTON
] != 0);
548 MouseButtonsStates
[2] = (QueueKeyStateTable
[VK_RBUTTON
] != 0);
554 /**********************************************************************
555 * GetAsyncKeyState (USER32.207)
557 * Determine if a key is or was pressed. retval has high-order
558 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
561 * This uses the variable AsyncMouseButtonsStates and
562 * AsyncKeyStateTable (set in event.c) which have the mouse button
563 * number or key number (whichever is applicable) set to true if the
564 * mouse or key had been depressed since the last call to
567 WORD WINAPI
GetAsyncKeyState(INT nKey
)
573 retval
= (AsyncMouseButtonsStates
[0] ? 0x0001 : 0) |
574 (MouseButtonsStates
[0] ? 0x8000 : 0);
577 retval
= (AsyncMouseButtonsStates
[1] ? 0x0001 : 0) |
578 (MouseButtonsStates
[1] ? 0x8000 : 0);
581 retval
= (AsyncMouseButtonsStates
[2] ? 0x0001 : 0) |
582 (MouseButtonsStates
[2] ? 0x8000 : 0);
585 retval
= AsyncKeyStateTable
[nKey
] |
586 ((InputKeyStateTable
[nKey
] & 0x80) ? 0x8000 : 0);
590 /* all states to false */
591 memset( AsyncMouseButtonsStates
, 0, sizeof(AsyncMouseButtonsStates
) );
592 memset( AsyncKeyStateTable
, 0, sizeof(AsyncKeyStateTable
) );
594 TRACE_(key
)("(%x) -> %x\n", nKey
, retval
);
598 /**********************************************************************
599 * GetAsyncKeyState16 (USER.249)
601 WORD WINAPI
GetAsyncKeyState16(INT16 nKey
)
603 return GetAsyncKeyState(nKey
);
606 /***********************************************************************
607 * IsUserIdle (USER.333)
609 BOOL16 WINAPI
IsUserIdle16(void)
611 if ( GetAsyncKeyState( VK_LBUTTON
) & 0x8000 )
614 if ( GetAsyncKeyState( VK_RBUTTON
) & 0x8000 )
617 if ( GetAsyncKeyState( VK_MBUTTON
) & 0x8000 )
620 /* Should check for screen saver activation here ... */
625 /**********************************************************************
626 * KBD_translate_accelerator
628 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
630 static BOOL
KBD_translate_accelerator(HWND hWnd
,LPMSG msg
,
631 BYTE fVirt
,WORD key
,WORD cmd
)
633 BOOL sendmsg
= FALSE
;
635 if(msg
->wParam
== key
)
637 if (msg
->message
== WM_CHAR
) {
638 if ( !(fVirt
& FALT
) && !(fVirt
& FVIRTKEY
) )
640 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n",
645 if(fVirt
& FVIRTKEY
) {
647 TRACE_(accel
)("found accel for virt_key %04x (scan %04x)\n",
648 msg
->wParam
,0xff & HIWORD(msg
->lParam
));
649 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
650 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
651 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
652 if(mask
== (fVirt
& (FSHIFT
| FCONTROL
| FALT
)))
655 TRACE_(accel
)(", but incorrect SHIFT/CTRL/ALT-state\n");
659 if (!(msg
->lParam
& 0x01000000)) /* no special_key */
661 if ((fVirt
& FALT
) && (msg
->lParam
& 0x20000000))
662 { /* ^^ ALT pressed */
663 TRACE_(accel
)("found accel for Alt-%c\n", msg
->wParam
&0xff);
670 if (sendmsg
) /* found an accelerator, but send a message... ? */
672 INT16 iSysStat
,iStat
,mesg
=0;
675 if (msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
681 if (!IsWindowEnabled(hWnd
))
685 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
687 hMenu
= (wndPtr
->dwStyle
& WS_CHILD
) ? 0 : (HMENU
)wndPtr
->wIDmenu
;
688 iSysStat
= (wndPtr
->hSysMenu
) ? GetMenuState(GetSubMenu16(wndPtr
->hSysMenu
, 0),
689 cmd
, MF_BYCOMMAND
) : -1 ;
690 iStat
= (hMenu
) ? GetMenuState(hMenu
,
691 cmd
, MF_BYCOMMAND
) : -1 ;
693 WIN_ReleaseWndPtr(wndPtr
);
697 if (iSysStat
& (MF_DISABLED
|MF_GRAYED
))
710 if (iStat
& (MF_DISABLED
|MF_GRAYED
))
720 if( mesg
==WM_COMMAND
) {
721 TRACE_(accel
)(", sending WM_COMMAND, wParam=%0x\n", 0x10000 | cmd
);
722 SendMessageA(hWnd
, mesg
, 0x10000 | cmd
, 0L);
723 } else if( mesg
==WM_SYSCOMMAND
) {
724 TRACE_(accel
)(", sending WM_SYSCOMMAND, wParam=%0x\n", cmd
);
725 SendMessageA(hWnd
, mesg
, cmd
, 0x00010000L
);
729 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
730 * #0: unknown (please report!)
731 * #1: for WM_KEYUP,WM_SYSKEYUP
732 * #2: mouse is captured
733 * #3: window is disabled
734 * #4: it's a disabled system menu option
735 * #5: it's a menu option, but window is iconic
736 * #6: it's a menu option, but disabled
738 TRACE_(accel
)(", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg
);
740 ERR_(accel
)(" unknown reason - please report!");
748 /**********************************************************************
749 * TranslateAccelerator (USER32.551)(USER32.552)(USER32.553)
751 INT WINAPI
TranslateAccelerator(HWND hWnd
, HACCEL hAccel
, LPMSG msg
)
754 LPACCEL16 lpAccelTbl
;
759 WARN_(accel
)("msg null; should hang here to be win compatible\n");
762 if (!hAccel
|| !(lpAccelTbl
= (LPACCEL16
) LockResource16(hAccel
)))
764 WARN_(accel
)("invalid accel handle=%x\n", hAccel
);
767 if ((msg
->message
!= WM_KEYDOWN
&&
768 msg
->message
!= WM_KEYUP
&&
769 msg
->message
!= WM_SYSKEYDOWN
&&
770 msg
->message
!= WM_SYSKEYUP
&&
771 msg
->message
!= WM_CHAR
)) return 0;
773 TRACE_(accel
)("TranslateAccelerators hAccel=%04x, hWnd=%04x,"
774 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%lx\n",
775 hAccel
,hWnd
,msg
->hwnd
,msg
->message
,msg
->wParam
,msg
->lParam
);
780 if (KBD_translate_accelerator(hWnd
,msg
,lpAccelTbl
[i
].fVirt
,
781 lpAccelTbl
[i
].key
,lpAccelTbl
[i
].cmd
))
783 } while ((lpAccelTbl
[i
++].fVirt
& 0x80) == 0);
784 WARN_(accel
)("couldn't translate accelerator key\n");
788 /**********************************************************************
789 * TranslateAccelerator16 (USER.178)
791 INT16 WINAPI
TranslateAccelerator16(HWND16 hWnd
, HACCEL16 hAccel
, LPMSG16 msg
)
793 LPACCEL16 lpAccelTbl
;
799 WARN_(accel
)("msg null; should hang here to be win compatible\n");
802 if (!hAccel
|| !(lpAccelTbl
= (LPACCEL16
) LockResource16(hAccel
)))
804 WARN_(accel
)("invalid accel handle=%x\n", hAccel
);
807 if ((msg
->message
!= WM_KEYDOWN
&&
808 msg
->message
!= WM_KEYUP
&&
809 msg
->message
!= WM_SYSKEYDOWN
&&
810 msg
->message
!= WM_SYSKEYUP
&&
811 msg
->message
!= WM_CHAR
)) return 0;
813 TRACE_(accel
)("TranslateAccelerators hAccel=%04x, hWnd=%04x,\
814 msg->hwnd=%04x, msg->message=%04x, wParam=%04x, lParam=%lx\n", hAccel
,hWnd
,msg
->hwnd
,msg
->message
,msg
->wParam
,msg
->lParam
);
816 STRUCT32_MSG16to32(msg
,&msg32
);
821 if (KBD_translate_accelerator(hWnd
,&msg32
,lpAccelTbl
[i
].fVirt
,
822 lpAccelTbl
[i
].key
,lpAccelTbl
[i
].cmd
))
824 } while ((lpAccelTbl
[i
++].fVirt
& 0x80) == 0);
825 WARN_(accel
)("couldn't translate accelerator key\n");
830 /**********************************************************************
831 * VkKeyScanA (USER32.573)
833 WORD WINAPI
VkKeyScanA(CHAR cChar
)
835 return VkKeyScan16(cChar
);
838 /******************************************************************************
839 * VkKeyScanW (USER32.576)
841 WORD WINAPI
VkKeyScanW(WCHAR cChar
)
843 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
846 /**********************************************************************
847 * VkKeyScanExA (USER32.574)
849 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
851 /* FIXME: complete workaround this is */
852 return VkKeyScan16(cChar
);
855 /******************************************************************************
856 * VkKeyScanExW (USER32.575)
858 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
860 /* FIXME: complete workaround this is */
861 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
864 /******************************************************************************
865 * GetKeyboardType (USER32.255)
867 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
869 return GetKeyboardType16(nTypeFlag
);
872 /******************************************************************************
873 * MapVirtualKeyA (USER32.383)
875 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
877 return MapVirtualKey16(code
,maptype
);
880 /******************************************************************************
881 * MapVirtualKeyW (USER32.385)
883 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
885 return MapVirtualKey16(code
,maptype
);
888 /******************************************************************************
889 * MapVirtualKeyExA (USER32.384)
891 UINT WINAPI
MapVirtualKeyExA(UINT code
, UINT maptype
, HKL hkl
)
894 FIXME_(keyboard
)("(%d,%d,0x%08lx), hkl unhandled!\n",code
,maptype
,(DWORD
)hkl
);
895 return MapVirtualKey16(code
,maptype
);
898 /****************************************************************************
899 * GetKBCodePage (USER32.246)
901 UINT WINAPI
GetKBCodePage(void)
903 return GetKBCodePage16();
906 /****************************************************************************
907 * GetKeyboardLayoutName16 (USER.477)
909 INT16 WINAPI
GetKeyboardLayoutName16(LPSTR pwszKLID
)
911 return GetKeyboardLayoutNameA(pwszKLID
);
914 /***********************************************************************
915 * GetKeyboardLayout (USER32.250)
917 * FIXME: - device handle for keyboard layout defaulted to
918 * the language id. This is the way Windows default works.
919 * - the thread identifier (dwLayout) is also ignored.
921 HKL WINAPI
GetKeyboardLayout(DWORD dwLayout
)
924 layout
= GetSystemDefaultLCID(); /* FIXME */
925 layout
|= (layout
<<16); /* FIXME */
926 TRACE_(keyboard
)("returning %08x\n",layout
);
930 /****************************************************************************
931 * GetKeyboardLayoutNameA (USER32.252)
933 INT WINAPI
GetKeyboardLayoutNameA(LPSTR pwszKLID
)
935 sprintf(pwszKLID
, "%08x",GetKeyboardLayout(0));
939 /****************************************************************************
940 * GetKeyboardLayoutNameW (USER32.253)
942 INT WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
945 int res
= GetKeyboardLayoutNameA(buf
);
946 lstrcpyAtoW(pwszKLID
,buf
);
950 /****************************************************************************
951 * GetKeyNameTextA (USER32.247)
953 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
955 return GetKeyNameText16(lParam
,lpBuffer
,nSize
);
958 /****************************************************************************
959 * GetKeyNameTextW (USER32.248)
961 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
964 LPSTR buf
= HeapAlloc( GetProcessHeap(), 0, nSize
);
965 if(buf
== NULL
) return 0; /* FIXME: is this the correct failure value?*/
966 res
= GetKeyNameTextA(lParam
,buf
,nSize
);
968 lstrcpynAtoW(lpBuffer
,buf
,nSize
);
969 HeapFree( GetProcessHeap(), 0, buf
);
973 /****************************************************************************
974 * ToAscii (USER32.546)
976 INT WINAPI
ToAscii( UINT virtKey
,UINT scanCode
,LPBYTE lpKeyState
,
977 LPWORD lpChar
,UINT flags
)
979 return ToAscii16(virtKey
,scanCode
,lpKeyState
,lpChar
,flags
);
982 /****************************************************************************
983 * ToAsciiEx (USER32.547)
985 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
986 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
988 /* FIXME: need true implementation */
989 return ToAscii16(virtKey
,scanCode
,lpKeyState
,lpChar
,flags
);
992 /**********************************************************************
993 * ActivateKeyboardLayout (USER32.1)
995 * Call ignored. WINE supports only system default keyboard layout.
997 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
999 TRACE_(keyboard
)("(%d, %d)\n", hLayout
, flags
);
1000 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
1005 /***********************************************************************
1006 * GetKeyboardLayoutList (USER32.251)
1008 * FIXME: Supports only the system default language and layout and
1009 * returns only 1 value.
1011 * Return number of values available if either input parm is
1012 * 0, per MS documentation.
1015 INT WINAPI
GetKeyboardLayoutList(INT nBuff
,HKL
*layouts
)
1017 TRACE_(keyboard
)("(%d,%p)\n",nBuff
,layouts
);
1018 if (!nBuff
|| !layouts
)
1021 layouts
[0] = GetKeyboardLayout(0);
1026 /***********************************************************************
1027 * RegisterHotKey (USER32.433)
1029 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
) {
1030 FIXME_(keyboard
)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd
,id
,modifiers
,vk
);
1034 /***********************************************************************
1035 * UnregisterHotKey (USER32.565)
1037 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
) {
1038 FIXME_(keyboard
)("(0x%08x,%d): stub\n",hwnd
,id
);
1043 /***********************************************************************
1044 * ToUnicode (USER32.548)
1046 INT WINAPI
ToUnicode(
1054 FIXME_(keyboard
)(": stub\n");
1058 /***********************************************************************
1059 * LoadKeyboardLayoutA (USER32.367)
1060 * Call ignored. WINE supports only system default keyboard layout.
1062 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
1064 TRACE_(keyboard
)("(%s, %d)\n", pwszKLID
, Flags
);
1065 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
1069 /***********************************************************************
1070 * LoadKeyboardLayoutW (USER32.368)
1072 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
1076 lstrcpynWtoA(buf
,pwszKLID
,8);
1078 return LoadKeyboardLayoutA(buf
, Flags
);