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
18 #include "wine/winbase16.h"
19 #include "wine/winuser16.h"
20 #include "wine/keyboard16.h"
28 #include "debugtools.h"
33 DECLARE_DEBUG_CHANNEL(accel
)
34 DECLARE_DEBUG_CHANNEL(event
)
35 DECLARE_DEBUG_CHANNEL(key
)
36 DECLARE_DEBUG_CHANNEL(keyboard
)
37 DECLARE_DEBUG_CHANNEL(win
)
39 static BOOL InputEnabled
= TRUE
;
40 BOOL SwappedButtons
= FALSE
;
42 BOOL MouseButtonsStates
[3];
43 BOOL AsyncMouseButtonsStates
[3];
44 BYTE InputKeyStateTable
[256];
45 BYTE QueueKeyStateTable
[256];
46 BYTE AsyncKeyStateTable
[256];
48 /* Storage for the USER-maintained mouse positions */
55 unsigned long count
: 16;
56 unsigned long code
: 8;
57 unsigned long extended
: 1;
58 unsigned long unused
: 2;
59 unsigned long win_internal
: 2;
60 unsigned long context
: 1;
61 unsigned long previous
: 1;
62 unsigned long transition
: 1;
67 /***********************************************************************
68 * keybd_event (USER32.583)
70 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
71 DWORD dwFlags
, DWORD dwExtraInfo
)
78 if (!InputEnabled
) return;
81 * If we are called by the Wine keyboard driver, use the additional
82 * info pointed to by the dwExtraInfo argument.
83 * Otherwise, we need to determine that info ourselves (probably
84 * less accurate, but we can't help that ...).
86 if ( !IsBadReadPtr( (LPVOID
)dwExtraInfo
, sizeof(WINE_KEYBDEVENT
) )
87 && ((WINE_KEYBDEVENT
*)dwExtraInfo
)->magic
== WINE_KEYBDEVENT_MAGIC
)
89 WINE_KEYBDEVENT
*wke
= (WINE_KEYBDEVENT
*)dwExtraInfo
;
95 time
= GetTickCount();
101 keylp
.lp1
.code
= bScan
;
102 keylp
.lp1
.extended
= (dwFlags
& KEYEVENTF_EXTENDEDKEY
) != 0;
103 keylp
.lp1
.win_internal
= 0; /* this has something to do with dialogs,
104 * don't remember where I read it - AK */
105 /* it's '1' under windows, when a dialog box appears
106 * and you press one of the underlined keys - DF*/
108 if ( dwFlags
& KEYEVENTF_KEYUP
)
110 BOOL sysKey
= (InputKeyStateTable
[VK_MENU
] & 0x80)
111 && !(InputKeyStateTable
[VK_CONTROL
] & 0x80)
112 && !(dwFlags
& KEYEVENTF_WINE_FORCEEXTENDED
); /* for Alt from AltGr */
114 InputKeyStateTable
[bVk
] &= ~0x80;
115 keylp
.lp1
.previous
= 1;
116 keylp
.lp1
.transition
= 1;
117 message
= sysKey
? WM_SYSKEYUP
: WM_KEYUP
;
121 keylp
.lp1
.previous
= (InputKeyStateTable
[bVk
] & 0x80) != 0;
122 keylp
.lp1
.transition
= 0;
124 if (!(InputKeyStateTable
[bVk
] & 0x80))
125 InputKeyStateTable
[bVk
] ^= 0x01;
126 InputKeyStateTable
[bVk
] |= 0x80;
128 message
= (InputKeyStateTable
[VK_MENU
] & 0x80)
129 && !(InputKeyStateTable
[VK_CONTROL
] & 0x80)
130 ? WM_SYSKEYDOWN
: WM_KEYDOWN
;
133 if ( message
== WM_SYSKEYDOWN
|| message
== WM_SYSKEYUP
)
134 keylp
.lp1
.context
= (InputKeyStateTable
[VK_MENU
] & 0x80) != 0; /* 1 if alt */
137 TRACE_(key
)(" wParam=%04X, lParam=%08lX\n", bVk
, keylp
.lp2
);
138 TRACE_(key
)(" InputKeyState=%X\n", InputKeyStateTable
[bVk
] );
140 hardware_event( message
, bVk
, keylp
.lp2
, PosX
, PosY
, time
, extra
);
143 /***********************************************************************
144 * WIN16_keybd_event (USER.289)
146 void WINAPI
WIN16_keybd_event( CONTEXT86
*context
)
150 if (AH_reg(context
) & 0x80) dwFlags
|= KEYEVENTF_KEYUP
;
151 if (BH_reg(context
) & 1 ) dwFlags
|= KEYEVENTF_EXTENDEDKEY
;
153 keybd_event( AL_reg(context
), BL_reg(context
),
154 dwFlags
, MAKELONG(SI_reg(context
), DI_reg(context
)) );
157 /***********************************************************************
158 * mouse_event (USER32.584)
160 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
161 DWORD cButtons
, DWORD dwExtraInfo
)
166 if (!InputEnabled
) return;
168 if ( dwFlags
& MOUSEEVENTF_MOVE
)
170 if ( dwFlags
& MOUSEEVENTF_ABSOLUTE
)
172 PosX
= (dx
* GetSystemMetrics(SM_CXSCREEN
)) >> 16;
173 PosY
= (dy
* GetSystemMetrics(SM_CYSCREEN
)) >> 16;
177 int width
= GetSystemMetrics(SM_CXSCREEN
);
178 int height
= GetSystemMetrics(SM_CYSCREEN
);
179 long posX
= (long) PosX
, posY
= (long) PosY
;
181 /* dx and dy can be negative numbers for relative movements */
185 /* Clip to the current screen size */
186 if (posX
< 0) PosX
= 0;
187 else if (posX
>= width
) PosX
= width
- 1;
190 if (posY
< 0) PosY
= 0;
191 else if (posY
>= height
) PosY
= height
- 1;
197 * If we are called by the Wine mouse driver, use the additional
198 * info pointed to by the dwExtraInfo argument.
199 * Otherwise, we need to determine that info ourselves (probably
200 * less accurate, but we can't help that ...).
202 if ( !IsBadReadPtr( (LPVOID
)dwExtraInfo
, sizeof(WINE_MOUSEEVENT
) )
203 && ((WINE_MOUSEEVENT
*)dwExtraInfo
)->magic
== WINE_MOUSEEVENT_MAGIC
)
205 WINE_MOUSEEVENT
*wme
= (WINE_MOUSEEVENT
*)dwExtraInfo
;
207 extra
= (DWORD
)wme
->hWnd
;
208 keyState
= wme
->keyState
;
210 if (keyState
!= GET_KEYSTATE()) {
211 /* We need to update the keystate with what X provides us */
212 MouseButtonsStates
[SwappedButtons
? 2 : 0] = (keyState
& MK_LBUTTON
? TRUE
: FALSE
);
213 MouseButtonsStates
[SwappedButtons
? 0 : 2] = (keyState
& MK_RBUTTON
? TRUE
: FALSE
);
214 MouseButtonsStates
[1] = (keyState
& MK_MBUTTON
? TRUE
: FALSE
);
215 InputKeyStateTable
[VK_SHIFT
] = (keyState
& MK_SHIFT
? 0x80 : 0);
216 InputKeyStateTable
[VK_CONTROL
] = (keyState
& MK_CONTROL
? 0x80 : 0);
221 time
= GetTickCount();
223 keyState
= GET_KEYSTATE();
225 if ( dwFlags
& MOUSEEVENTF_MOVE
)
227 /* We have to actually move the cursor */
228 SetCursorPos( PosX
, PosY
);
233 if ( dwFlags
& MOUSEEVENTF_MOVE
)
235 hardware_event( WM_MOUSEMOVE
,
236 keyState
, 0L, PosX
, PosY
, time
, extra
);
238 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_LEFTDOWN
: MOUSEEVENTF_RIGHTDOWN
) )
240 MouseButtonsStates
[0] = AsyncMouseButtonsStates
[0] = TRUE
;
241 hardware_event( WM_LBUTTONDOWN
,
242 keyState
, 0L, PosX
, PosY
, time
, extra
);
244 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_LEFTUP
: MOUSEEVENTF_RIGHTUP
) )
246 MouseButtonsStates
[0] = FALSE
;
247 hardware_event( WM_LBUTTONUP
,
248 keyState
, 0L, PosX
, PosY
, time
, extra
);
250 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_RIGHTDOWN
: MOUSEEVENTF_LEFTDOWN
) )
252 MouseButtonsStates
[2] = AsyncMouseButtonsStates
[2] = TRUE
;
253 hardware_event( WM_RBUTTONDOWN
,
254 keyState
, 0L, PosX
, PosY
, time
, extra
);
256 if ( dwFlags
& (!SwappedButtons
? MOUSEEVENTF_RIGHTUP
: MOUSEEVENTF_LEFTUP
) )
258 MouseButtonsStates
[2] = FALSE
;
259 hardware_event( WM_RBUTTONUP
,
260 keyState
, 0L, PosX
, PosY
, time
, extra
);
262 if ( dwFlags
& MOUSEEVENTF_MIDDLEDOWN
)
264 MouseButtonsStates
[1] = AsyncMouseButtonsStates
[1] = TRUE
;
265 hardware_event( WM_MBUTTONDOWN
,
266 keyState
, 0L, PosX
, PosY
, time
, extra
);
268 if ( dwFlags
& MOUSEEVENTF_MIDDLEUP
)
270 MouseButtonsStates
[1] = FALSE
;
271 hardware_event( WM_MBUTTONUP
,
272 keyState
, 0L, PosX
, PosY
, time
, extra
);
276 /***********************************************************************
277 * WIN16_mouse_event (USER.299)
279 void WINAPI
WIN16_mouse_event( CONTEXT86
*context
)
281 mouse_event( AX_reg(context
), BX_reg(context
), CX_reg(context
),
282 DX_reg(context
), MAKELONG(SI_reg(context
), DI_reg(context
)) );
285 /***********************************************************************
286 * GetMouseEventProc (USER.337)
288 FARPROC16 WINAPI
GetMouseEventProc16(void)
290 HMODULE16 hmodule
= GetModuleHandle16("USER");
291 return NE_GetEntryPoint( hmodule
, NE_GetOrdinal( hmodule
, "mouse_event" ));
295 /**********************************************************************
296 * EnableHardwareInput (USER.331)
298 BOOL16 WINAPI
EnableHardwareInput16(BOOL16 bEnable
)
300 BOOL16 bOldState
= InputEnabled
;
301 FIXME_(event
)("(%d) - stub\n", bEnable
);
302 InputEnabled
= bEnable
;
307 /***********************************************************************
308 * SwapMouseButton16 (USER.186)
310 BOOL16 WINAPI
SwapMouseButton16( BOOL16 fSwap
)
312 BOOL16 ret
= SwappedButtons
;
313 SwappedButtons
= fSwap
;
318 /***********************************************************************
319 * SwapMouseButton32 (USER32.537)
321 BOOL WINAPI
SwapMouseButton( BOOL fSwap
)
323 BOOL ret
= SwappedButtons
;
324 SwappedButtons
= fSwap
;
328 /**********************************************************************
331 * We need this to be able to generate double click messages
332 * when menu code captures mouse in the window without CS_DBLCLK style.
334 HWND
EVENT_Capture(HWND hwnd
, INT16 ht
)
336 HWND capturePrev
= 0, captureWnd
= 0;
337 MESSAGEQUEUE
*pMsgQ
= 0, *pCurMsgQ
= 0;
341 /* Get the messageQ for the current thread */
342 if (!(pCurMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
344 WARN_(win
)("\tCurrent message queue not found. Exiting!\n" );
348 /* Get the current capture window from the perQ data of the current message Q */
349 capturePrev
= PERQDATA_GetCaptureWnd( pCurMsgQ
->pQData
);
358 wndPtr
= WIN_FindWndPtr( hwnd
);
361 TRACE_(win
)("(0x%04x)\n", hwnd
);
367 /* Update the perQ capture window and send messages */
368 if( capturePrev
!= captureWnd
)
372 /* Retrieve the message queue associated with this window */
373 pMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( wndPtr
->hmemTaskQ
);
376 WARN_(win
)("\tMessage queue not found. Exiting!\n" );
380 /* Make sure that message queue for the window we are setting capture to
381 * shares the same perQ data as the current threads message queue.
383 if ( pCurMsgQ
->pQData
!= pMsgQ
->pQData
)
387 PERQDATA_SetCaptureWnd( pCurMsgQ
->pQData
, captureWnd
);
388 PERQDATA_SetCaptureInfo( pCurMsgQ
->pQData
, captureHT
);
392 WND
* wndPtr
= WIN_FindWndPtr( capturePrev
);
393 if( wndPtr
&& (wndPtr
->flags
& WIN_ISWIN32
) )
394 SendMessageA( capturePrev
, WM_CAPTURECHANGED
, 0L, hwnd
);
395 WIN_ReleaseWndPtr(wndPtr
);
400 /* Unlock the queues before returning */
402 QUEUE_Unlock( pMsgQ
);
404 QUEUE_Unlock( pCurMsgQ
);
406 WIN_ReleaseWndPtr(wndPtr
);
411 /**********************************************************************
412 * SetCapture16 (USER.18)
414 HWND16 WINAPI
SetCapture16( HWND16 hwnd
)
416 return (HWND16
)EVENT_Capture( hwnd
, HTCLIENT
);
420 /**********************************************************************
421 * SetCapture32 (USER32.464)
423 HWND WINAPI
SetCapture( HWND hwnd
)
425 return EVENT_Capture( hwnd
, HTCLIENT
);
429 /**********************************************************************
430 * ReleaseCapture (USER.19) (USER32.439)
432 BOOL WINAPI
ReleaseCapture(void)
434 return (EVENT_Capture( 0, 0 ) != 0);
438 /**********************************************************************
439 * GetCapture16 (USER.236)
441 HWND16 WINAPI
GetCapture16(void)
443 return (HWND16
)GetCapture();
446 /**********************************************************************
447 * GetCapture32 (USER32.208)
449 HWND WINAPI
GetCapture(void)
451 MESSAGEQUEUE
*pCurMsgQ
= 0;
452 HWND hwndCapture
= 0;
454 /* Get the messageQ for the current thread */
455 if (!(pCurMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
457 TRACE_(win
)("GetCapture32: Current message queue not found. Exiting!\n" );
461 /* Get the current capture window from the perQ data of the current message Q */
462 hwndCapture
= PERQDATA_GetCaptureWnd( pCurMsgQ
->pQData
);
464 QUEUE_Unlock( pCurMsgQ
);
468 /**********************************************************************
469 * GetKeyState (USER.106)
471 INT16 WINAPI
GetKeyState16(INT16 vkey
)
473 return GetKeyState(vkey
);
476 /**********************************************************************
477 * GetKeyState (USER32.249)
479 * An application calls the GetKeyState function in response to a
480 * keyboard-input message. This function retrieves the state of the key
481 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
483 SHORT WINAPI
GetKeyState(INT vkey
)
489 case VK_LBUTTON
: /* VK_LBUTTON is 1 */
490 retval
= MouseButtonsStates
[0] ? 0x8000 : 0;
492 case VK_MBUTTON
: /* VK_MBUTTON is 4 */
493 retval
= MouseButtonsStates
[1] ? 0x8000 : 0;
495 case VK_RBUTTON
: /* VK_RBUTTON is 2 */
496 retval
= MouseButtonsStates
[2] ? 0x8000 : 0;
499 if (vkey
>= 'a' && vkey
<= 'z')
501 retval
= ( (WORD
)(QueueKeyStateTable
[vkey
] & 0x80) << 8 ) |
502 (WORD
)(QueueKeyStateTable
[vkey
] & 0x01);
504 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
508 /**********************************************************************
509 * GetKeyboardState (USER.222)(USER32.254)
511 * An application calls the GetKeyboardState function in response to a
512 * keyboard-input message. This function retrieves the state of the keyboard
513 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
515 BOOL WINAPI
GetKeyboardState(LPBYTE lpKeyState
)
517 TRACE_(key
)("(%p)\n", lpKeyState
);
518 if (lpKeyState
!= NULL
) {
519 QueueKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] ? 0x80 : 0;
520 QueueKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] ? 0x80 : 0;
521 QueueKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] ? 0x80 : 0;
522 memcpy(lpKeyState
, QueueKeyStateTable
, 256);
528 /**********************************************************************
529 * SetKeyboardState (USER.223)(USER32.484)
531 BOOL WINAPI
SetKeyboardState(LPBYTE lpKeyState
)
533 TRACE_(key
)("(%p)\n", lpKeyState
);
534 if (lpKeyState
!= NULL
) {
535 memcpy(QueueKeyStateTable
, lpKeyState
, 256);
536 MouseButtonsStates
[0] = (QueueKeyStateTable
[VK_LBUTTON
] != 0);
537 MouseButtonsStates
[1] = (QueueKeyStateTable
[VK_MBUTTON
] != 0);
538 MouseButtonsStates
[2] = (QueueKeyStateTable
[VK_RBUTTON
] != 0);
544 /**********************************************************************
545 * GetAsyncKeyState32 (USER32.207)
547 * Determine if a key is or was pressed. retval has high-order
548 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
551 * This uses the variable AsyncMouseButtonsStates and
552 * AsyncKeyStateTable (set in event.c) which have the mouse button
553 * number or key number (whichever is applicable) set to true if the
554 * mouse or key had been depressed since the last call to
557 WORD WINAPI
GetAsyncKeyState(INT nKey
)
563 retval
= (AsyncMouseButtonsStates
[0] ? 0x0001 : 0) |
564 (MouseButtonsStates
[0] ? 0x8000 : 0);
567 retval
= (AsyncMouseButtonsStates
[1] ? 0x0001 : 0) |
568 (MouseButtonsStates
[1] ? 0x8000 : 0);
571 retval
= (AsyncMouseButtonsStates
[2] ? 0x0001 : 0) |
572 (MouseButtonsStates
[2] ? 0x8000 : 0);
575 retval
= AsyncKeyStateTable
[nKey
] |
576 ((InputKeyStateTable
[nKey
] & 0x80) ? 0x8000 : 0);
580 /* all states to false */
581 memset( AsyncMouseButtonsStates
, 0, sizeof(AsyncMouseButtonsStates
) );
582 memset( AsyncKeyStateTable
, 0, sizeof(AsyncKeyStateTable
) );
584 TRACE_(key
)("(%x) -> %x\n", nKey
, retval
);
588 /**********************************************************************
589 * GetAsyncKeyState16 (USER.249)
591 WORD WINAPI
GetAsyncKeyState16(INT16 nKey
)
593 return GetAsyncKeyState(nKey
);
596 /***********************************************************************
597 * IsUserIdle (USER.333)
599 BOOL16 WINAPI
IsUserIdle16(void)
601 if ( GetAsyncKeyState( VK_LBUTTON
) & 0x8000 )
604 if ( GetAsyncKeyState( VK_RBUTTON
) & 0x8000 )
607 if ( GetAsyncKeyState( VK_MBUTTON
) & 0x8000 )
610 /* Should check for screen saver activation here ... */
615 /**********************************************************************
616 * KBD_translate_accelerator
618 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
620 static BOOL
KBD_translate_accelerator(HWND hWnd
,LPMSG msg
,
621 BYTE fVirt
,WORD key
,WORD cmd
)
623 BOOL sendmsg
= FALSE
;
625 if(msg
->wParam
== key
)
627 if (msg
->message
== WM_CHAR
) {
628 if ( !(fVirt
& FALT
) && !(fVirt
& FVIRTKEY
) )
630 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n",
635 if(fVirt
& FVIRTKEY
) {
637 TRACE_(accel
)("found accel for virt_key %04x (scan %04x)\n",
638 msg
->wParam
,0xff & HIWORD(msg
->lParam
));
639 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
640 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
641 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
642 if(mask
== (fVirt
& (FSHIFT
| FCONTROL
| FALT
)))
645 TRACE_(accel
)(", but incorrect SHIFT/CTRL/ALT-state\n");
649 if (!(msg
->lParam
& 0x01000000)) /* no special_key */
651 if ((fVirt
& FALT
) && (msg
->lParam
& 0x20000000))
652 { /* ^^ ALT pressed */
653 TRACE_(accel
)("found accel for Alt-%c\n", msg
->wParam
&0xff);
660 if (sendmsg
) /* found an accelerator, but send a message... ? */
662 INT16 iSysStat
,iStat
,mesg
=0;
665 if (msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
671 if (!IsWindowEnabled(hWnd
))
675 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
677 hMenu
= (wndPtr
->dwStyle
& WS_CHILD
) ? 0 : (HMENU
)wndPtr
->wIDmenu
;
678 iSysStat
= (wndPtr
->hSysMenu
) ? GetMenuState(GetSubMenu16(wndPtr
->hSysMenu
, 0),
679 cmd
, MF_BYCOMMAND
) : -1 ;
680 iStat
= (hMenu
) ? GetMenuState(hMenu
,
681 cmd
, MF_BYCOMMAND
) : -1 ;
683 WIN_ReleaseWndPtr(wndPtr
);
687 if (iSysStat
& (MF_DISABLED
|MF_GRAYED
))
700 if (iStat
& (MF_DISABLED
|MF_GRAYED
))
710 if ( mesg
==WM_COMMAND
|| mesg
==WM_SYSCOMMAND
)
712 TRACE_(accel
)(", sending %s, wParam=%0x\n",
713 mesg
==WM_COMMAND
? "WM_COMMAND" : "WM_SYSCOMMAND",
715 SendMessageA(hWnd
, mesg
, cmd
, 0x00010000L
);
719 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
720 * #0: unknown (please report!)
721 * #1: for WM_KEYUP,WM_SYSKEYUP
722 * #2: mouse is captured
723 * #3: window is disabled
724 * #4: it's a disabled system menu option
725 * #5: it's a menu option, but window is iconic
726 * #6: it's a menu option, but disabled
728 TRACE_(accel
)(", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg
);
730 ERR_(accel
)(" unknown reason - please report!");
738 /**********************************************************************
739 * TranslateAccelerator32 (USER32.551)(USER32.552)(USER32.553)
741 INT WINAPI
TranslateAccelerator(HWND hWnd
, HACCEL hAccel
, LPMSG msg
)
744 LPACCEL16 lpAccelTbl
;
749 WARN_(accel
)("msg null; should hang here to be win compatible\n");
752 if (!hAccel
|| !(lpAccelTbl
= (LPACCEL16
) LockResource16(hAccel
)))
754 WARN_(accel
)("invalid accel handle=%x\n", hAccel
);
757 if ((msg
->message
!= WM_KEYDOWN
&&
758 msg
->message
!= WM_KEYUP
&&
759 msg
->message
!= WM_SYSKEYDOWN
&&
760 msg
->message
!= WM_SYSKEYUP
&&
761 msg
->message
!= WM_CHAR
)) return 0;
763 TRACE_(accel
)("TranslateAccelerators hAccel=%04x, hWnd=%04x,"
764 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%lx\n",
765 hAccel
,hWnd
,msg
->hwnd
,msg
->message
,msg
->wParam
,msg
->lParam
);
770 if (KBD_translate_accelerator(hWnd
,msg
,lpAccelTbl
[i
].fVirt
,
771 lpAccelTbl
[i
].key
,lpAccelTbl
[i
].cmd
))
773 } while ((lpAccelTbl
[i
++].fVirt
& 0x80) == 0);
774 WARN_(accel
)("couldn't translate accelerator key\n");
778 /**********************************************************************
779 * TranslateAccelerator16 (USER.178)
781 INT16 WINAPI
TranslateAccelerator16(HWND16 hWnd
, HACCEL16 hAccel
, LPMSG16 msg
)
783 LPACCEL16 lpAccelTbl
;
789 WARN_(accel
)("msg null; should hang here to be win compatible\n");
792 if (!hAccel
|| !(lpAccelTbl
= (LPACCEL16
) LockResource16(hAccel
)))
794 WARN_(accel
)("invalid accel handle=%x\n", hAccel
);
797 if ((msg
->message
!= WM_KEYDOWN
&&
798 msg
->message
!= WM_KEYUP
&&
799 msg
->message
!= WM_SYSKEYDOWN
&&
800 msg
->message
!= WM_SYSKEYUP
&&
801 msg
->message
!= WM_CHAR
)) return 0;
803 TRACE_(accel
)("TranslateAccelerators hAccel=%04x, hWnd=%04x,\
804 msg->hwnd=%04x, msg->message=%04x, wParam=%04x, lParam=%lx\n", hAccel
,hWnd
,msg
->hwnd
,msg
->message
,msg
->wParam
,msg
->lParam
);
806 STRUCT32_MSG16to32(msg
,&msg32
);
811 if (KBD_translate_accelerator(hWnd
,&msg32
,lpAccelTbl
[i
].fVirt
,
812 lpAccelTbl
[i
].key
,lpAccelTbl
[i
].cmd
))
814 } while ((lpAccelTbl
[i
++].fVirt
& 0x80) == 0);
815 WARN_(accel
)("couldn't translate accelerator key\n");
820 /**********************************************************************
821 * VkKeyScanA (USER32.573)
823 WORD WINAPI
VkKeyScanA(CHAR cChar
)
825 return VkKeyScan16(cChar
);
828 /******************************************************************************
829 * VkKeyScanW (USER32.576)
831 WORD WINAPI
VkKeyScanW(WCHAR cChar
)
833 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
836 /**********************************************************************
837 * VkKeyScanExA (USER32.574)
839 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
841 /* FIXME: complete workaround this is */
842 return VkKeyScan16(cChar
);
845 /******************************************************************************
846 * VkKeyScanExW (USER32.575)
848 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
850 /* FIXME: complete workaround this is */
851 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
854 /******************************************************************************
855 * GetKeyboardType32 (USER32.255)
857 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
859 return GetKeyboardType16(nTypeFlag
);
862 /******************************************************************************
863 * MapVirtualKey32A (USER32.383)
865 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
867 return MapVirtualKey16(code
,maptype
);
870 /******************************************************************************
871 * MapVirtualKey32W (USER32.385)
873 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
875 return MapVirtualKey16(code
,maptype
);
878 /******************************************************************************
879 * MapVirtualKeyEx32A (USER32.384)
881 UINT WINAPI
MapVirtualKeyEx32A(UINT code
, UINT maptype
, HKL hkl
)
884 FIXME_(keyboard
)("(%d,%d,0x%08lx), hkl unhandled!\n",code
,maptype
,(DWORD
)hkl
);
885 return MapVirtualKey16(code
,maptype
);
888 /****************************************************************************
889 * GetKBCodePage32 (USER32.246)
891 UINT WINAPI
GetKBCodePage(void)
893 return GetKBCodePage16();
896 /****************************************************************************
897 * GetKeyboardLayoutName16 (USER.477)
899 INT16 WINAPI
GetKeyboardLayoutName16(LPSTR pwszKLID
)
901 return GetKeyboardLayoutNameA(pwszKLID
);
904 /***********************************************************************
905 * GetKeyboardLayout (USER32.250)
907 * FIXME: - device handle for keyboard layout defaulted to
908 * the language id. This is the way Windows default works.
909 * - the thread identifier (dwLayout) is also ignored.
911 HKL WINAPI
GetKeyboardLayout(DWORD dwLayout
)
914 layout
= GetSystemDefaultLCID(); /* FIXME */
915 layout
|= (layout
<<16); /* FIXME */
916 TRACE_(keyboard
)("returning %08x\n",layout
);
920 /****************************************************************************
921 * GetKeyboardLayoutName32A (USER32.252)
923 INT WINAPI
GetKeyboardLayoutNameA(LPSTR pwszKLID
)
925 sprintf(pwszKLID
, "%08x",GetKeyboardLayout(0));
929 /****************************************************************************
930 * GetKeyboardLayoutName32W (USER32.253)
932 INT WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
934 LPSTR buf
= HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
935 int res
= GetKeyboardLayoutNameA(buf
);
936 lstrcpyAtoW(pwszKLID
,buf
);
937 HeapFree( GetProcessHeap(), 0, buf
);
941 /****************************************************************************
942 * GetKeyNameText32A (USER32.247)
944 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
946 return GetKeyNameText16(lParam
,lpBuffer
,nSize
);
949 /****************************************************************************
950 * GetKeyNameText32W (USER32.248)
952 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
954 LPSTR buf
= HEAP_xalloc( GetProcessHeap(), 0, nSize
);
955 int res
= GetKeyNameTextA(lParam
,buf
,nSize
);
957 lstrcpynAtoW(lpBuffer
,buf
,nSize
);
958 HeapFree( GetProcessHeap(), 0, buf
);
962 /****************************************************************************
963 * ToAscii32 (USER32.546)
965 INT WINAPI
ToAscii( UINT virtKey
,UINT scanCode
,LPBYTE lpKeyState
,
966 LPWORD lpChar
,UINT flags
)
968 return ToAscii16(virtKey
,scanCode
,lpKeyState
,lpChar
,flags
);
971 /****************************************************************************
972 * ToAscii32 (USER32.547)
974 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
975 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
977 /* FIXME: need true implementation */
978 return ToAscii16(virtKey
,scanCode
,lpKeyState
,lpChar
,flags
);
981 /**********************************************************************
982 * ActivateKeyboardLayout32 (USER32.1)
984 * Call ignored. WINE supports only system default keyboard layout.
986 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
988 TRACE_(keyboard
)("(%d, %d)\n", hLayout
, flags
);
989 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
994 /***********************************************************************
995 * GetKeyboardLayoutList (USER32.251)
997 * FIXME: Supports only the system default language and layout and
998 * returns only 1 value.
1000 * Return number of values available if either input parm is
1001 * 0, per MS documentation.
1004 INT WINAPI
GetKeyboardLayoutList(INT nBuff
,HKL
*layouts
)
1006 TRACE_(keyboard
)("(%d,%p)\n",nBuff
,layouts
);
1007 if (!nBuff
|| !layouts
)
1010 layouts
[0] = GetKeyboardLayout(0);
1015 /***********************************************************************
1016 * RegisterHotKey (USER32.433)
1018 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
) {
1019 FIXME_(keyboard
)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd
,id
,modifiers
,vk
);
1023 /***********************************************************************
1024 * UnregisterHotKey (USER32.565)
1026 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
) {
1027 FIXME_(keyboard
)("(0x%08x,%d): stub\n",hwnd
,id
);
1032 /***********************************************************************
1033 * ToUnicode32 (USER32.548)
1035 INT WINAPI
ToUnicode(
1043 FIXME_(keyboard
)(": stub\n");
1047 /***********************************************************************
1048 * LoadKeyboardLayout32A (USER32.367)
1049 * Call ignored. WINE supports only system default keyboard layout.
1051 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
1053 TRACE_(keyboard
)("(%s, %d)\n", pwszKLID
, Flags
);
1054 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
1058 /***********************************************************************
1059 * LoadKeyboardLayout32W (USER32.368)
1061 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
1063 LPSTR buf
= HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
1065 lstrcpynWtoA(buf
,pwszKLID
,8);
1067 res
= LoadKeyboardLayoutA(buf
, Flags
);
1068 HeapFree( GetProcessHeap(), 0, buf
);