Workaround for SuSE 7 2.2.16 kernel bug.
[wine.git] / windows / input.c
bloba5c88c31b6c72b50ae9849188651738686e5d264
1 /*
2 * USER Input processing
4 * Copyright 1993 Bob Amstadt
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1997 David Faure
7 * Copyright 1998 Morten Welinder
8 * Copyright 1998 Ulrich Weigand
12 #include <stdlib.h>
13 #include <string.h>
14 #include <stdio.h>
15 #include <ctype.h>
16 #include <assert.h>
18 #include "windef.h"
19 #include "winnls.h"
20 #include "winbase.h"
21 #include "wingdi.h"
22 #include "winuser.h"
23 #include "wine/winbase16.h"
24 #include "wine/winuser16.h"
25 #include "wine/keyboard16.h"
26 #include "win.h"
27 #include "heap.h"
28 #include "input.h"
29 #include "keyboard.h"
30 #include "mouse.h"
31 #include "message.h"
32 #include "queue.h"
33 #include "debugtools.h"
34 #include "winerror.h"
35 #include "task.h"
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 static BOOL SwappedButtons;
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 */
52 static DWORD PosX, PosY;
54 #define GET_KEYSTATE() \
55 ((MouseButtonsStates[SwappedButtons ? 2 : 0] ? MK_LBUTTON : 0) | \
56 (MouseButtonsStates[1] ? MK_RBUTTON : 0) | \
57 (MouseButtonsStates[SwappedButtons ? 0 : 2] ? MK_MBUTTON : 0) | \
58 (InputKeyStateTable[VK_SHIFT] & 0x80 ? MK_SHIFT : 0) | \
59 (InputKeyStateTable[VK_CONTROL] & 0x80 ? MK_CONTROL : 0))
61 typedef union
63 struct
65 unsigned long count : 16;
66 unsigned long code : 8;
67 unsigned long extended : 1;
68 unsigned long unused : 2;
69 unsigned long win_internal : 2;
70 unsigned long context : 1;
71 unsigned long previous : 1;
72 unsigned long transition : 1;
73 } lp1;
74 unsigned long lp2;
75 } KEYLP;
77 /***********************************************************************
78 * keybd_event (USER32.@)
80 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
81 DWORD dwFlags, DWORD dwExtraInfo )
83 DWORD time, extra;
84 WORD message;
85 KEYLP keylp;
86 keylp.lp2 = 0;
88 if (!InputEnabled) return;
91 * If we are called by the Wine keyboard driver, use the additional
92 * info pointed to by the dwExtraInfo argument.
93 * Otherwise, we need to determine that info ourselves (probably
94 * less accurate, but we can't help that ...).
96 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_KEYBDEVENT) )
97 && ((WINE_KEYBDEVENT *)dwExtraInfo)->magic == WINE_KEYBDEVENT_MAGIC )
99 WINE_KEYBDEVENT *wke = (WINE_KEYBDEVENT *)dwExtraInfo;
100 time = wke->time;
101 extra = 0;
103 else
105 time = GetTickCount();
106 extra = dwExtraInfo;
110 keylp.lp1.count = 1;
111 keylp.lp1.code = bScan;
112 keylp.lp1.extended = (dwFlags & KEYEVENTF_EXTENDEDKEY) != 0;
113 keylp.lp1.win_internal = 0; /* this has something to do with dialogs,
114 * don't remember where I read it - AK */
115 /* it's '1' under windows, when a dialog box appears
116 * and you press one of the underlined keys - DF*/
118 if ( dwFlags & KEYEVENTF_KEYUP )
120 BOOL sysKey = (InputKeyStateTable[VK_MENU] & 0x80)
121 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
122 && !(dwFlags & KEYEVENTF_WINE_FORCEEXTENDED); /* for Alt from AltGr */
124 InputKeyStateTable[bVk] &= ~0x80;
125 keylp.lp1.previous = 1;
126 keylp.lp1.transition = 1;
127 message = sysKey ? WM_SYSKEYUP : WM_KEYUP;
129 else
131 keylp.lp1.previous = (InputKeyStateTable[bVk] & 0x80) != 0;
132 keylp.lp1.transition = 0;
134 if (!(InputKeyStateTable[bVk] & 0x80))
135 InputKeyStateTable[bVk] ^= 0x01;
136 InputKeyStateTable[bVk] |= 0x80;
138 message = (InputKeyStateTable[VK_MENU] & 0x80)
139 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
140 ? WM_SYSKEYDOWN : WM_KEYDOWN;
143 if ( message == WM_SYSKEYDOWN || message == WM_SYSKEYUP )
144 keylp.lp1.context = (InputKeyStateTable[VK_MENU] & 0x80) != 0; /* 1 if alt */
147 TRACE_(key)(" wParam=%04X, lParam=%08lX\n", bVk, keylp.lp2 );
148 TRACE_(key)(" InputKeyState=%X\n", InputKeyStateTable[bVk] );
150 hardware_event( message, bVk, keylp.lp2, PosX, PosY, time, extra );
153 /***********************************************************************
154 * keybd_event (USER.289)
156 void WINAPI WIN16_keybd_event( CONTEXT86 *context )
158 DWORD dwFlags = 0;
160 if (AH_reg(context) & 0x80) dwFlags |= KEYEVENTF_KEYUP;
161 if (BH_reg(context) & 1 ) dwFlags |= KEYEVENTF_EXTENDEDKEY;
163 keybd_event( AL_reg(context), BL_reg(context),
164 dwFlags, MAKELONG(SI_reg(context), DI_reg(context)) );
167 /***********************************************************************
168 * mouse_event (USER32.@)
170 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
171 DWORD cButtons, DWORD dwExtraInfo )
173 DWORD time, extra;
174 DWORD keyState;
176 if (!InputEnabled) return;
178 if ( dwFlags & MOUSEEVENTF_MOVE )
180 if ( dwFlags & MOUSEEVENTF_ABSOLUTE )
182 PosX = (dx * GetSystemMetrics(SM_CXSCREEN)) >> 16;
183 PosY = (dy * GetSystemMetrics(SM_CYSCREEN)) >> 16;
185 else
187 int width = GetSystemMetrics(SM_CXSCREEN);
188 int height = GetSystemMetrics(SM_CYSCREEN);
189 long posX = (long) PosX, posY = (long) PosY;
191 /* dx and dy can be negative numbers for relative movements */
192 posX += (long) dx;
193 posY += (long) dy;
195 /* Clip to the current screen size */
196 if (posX < 0) PosX = 0;
197 else if (posX >= width) PosX = width - 1;
198 else PosX = posX;
200 if (posY < 0) PosY = 0;
201 else if (posY >= height) PosY = height - 1;
202 else PosY = posY;
207 * If we are called by the Wine mouse driver, use the additional
208 * info pointed to by the dwExtraInfo argument.
209 * Otherwise, we need to determine that info ourselves (probably
210 * less accurate, but we can't help that ...).
212 if (dwExtraInfo && !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_MOUSEEVENT) )
213 && ((WINE_MOUSEEVENT *)dwExtraInfo)->magic == WINE_MOUSEEVENT_MAGIC )
215 WINE_MOUSEEVENT *wme = (WINE_MOUSEEVENT *)dwExtraInfo;
216 time = wme->time;
217 extra = (DWORD)wme->hWnd;
218 keyState = wme->keyState;
220 if (keyState != GET_KEYSTATE()) {
221 /* We need to update the keystate with what X provides us */
222 MouseButtonsStates[SwappedButtons ? 2 : 0] = (keyState & MK_LBUTTON ? TRUE : FALSE);
223 MouseButtonsStates[SwappedButtons ? 0 : 2] = (keyState & MK_RBUTTON ? TRUE : FALSE);
224 MouseButtonsStates[1] = (keyState & MK_MBUTTON ? TRUE : FALSE);
225 InputKeyStateTable[VK_SHIFT] = (keyState & MK_SHIFT ? 0x80 : 0);
226 InputKeyStateTable[VK_CONTROL] = (keyState & MK_CONTROL ? 0x80 : 0);
229 else
231 time = GetTickCount();
232 extra = dwExtraInfo;
233 keyState = GET_KEYSTATE();
235 if ( dwFlags & MOUSEEVENTF_MOVE )
237 /* We have to actually move the cursor */
238 SetCursorPos( PosX, PosY );
243 if ( dwFlags & MOUSEEVENTF_MOVE )
245 hardware_event( WM_MOUSEMOVE,
246 keyState, 0L, PosX, PosY, time, extra );
248 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN) )
250 MouseButtonsStates[0] = AsyncMouseButtonsStates[0] = TRUE;
251 hardware_event( WM_LBUTTONDOWN,
252 keyState, 0L, PosX, PosY, time, extra );
254 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP) )
256 MouseButtonsStates[0] = FALSE;
257 hardware_event( WM_LBUTTONUP,
258 keyState, 0L, PosX, PosY, time, extra );
260 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN) )
262 MouseButtonsStates[2] = AsyncMouseButtonsStates[2] = TRUE;
263 hardware_event( WM_RBUTTONDOWN,
264 keyState, 0L, PosX, PosY, time, extra );
266 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_LEFTUP) )
268 MouseButtonsStates[2] = FALSE;
269 hardware_event( WM_RBUTTONUP,
270 keyState, 0L, PosX, PosY, time, extra );
272 if ( dwFlags & MOUSEEVENTF_MIDDLEDOWN )
274 MouseButtonsStates[1] = AsyncMouseButtonsStates[1] = TRUE;
275 hardware_event( WM_MBUTTONDOWN,
276 keyState, 0L, PosX, PosY, time, extra );
278 if ( dwFlags & MOUSEEVENTF_MIDDLEUP )
280 MouseButtonsStates[1] = FALSE;
281 hardware_event( WM_MBUTTONUP,
282 keyState, 0L, PosX, PosY, time, extra );
284 if ( dwFlags & MOUSEEVENTF_WHEEL )
286 hardware_event( WM_MOUSEWHEEL,
287 keyState, 0L, PosX, PosY, time, extra );
291 /***********************************************************************
292 * mouse_event (USER.299)
294 void WINAPI WIN16_mouse_event( CONTEXT86 *context )
296 mouse_event( AX_reg(context), BX_reg(context), CX_reg(context),
297 DX_reg(context), MAKELONG(SI_reg(context), DI_reg(context)) );
300 /***********************************************************************
301 * GetMouseEventProc (USER.337)
303 FARPROC16 WINAPI GetMouseEventProc16(void)
305 HMODULE16 hmodule = GetModuleHandle16("USER");
306 return GetProcAddress16( hmodule, "mouse_event" );
310 /**********************************************************************
311 * EnableHardwareInput (USER.331)
313 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
315 BOOL16 bOldState = InputEnabled;
316 FIXME_(event)("(%d) - stub\n", bEnable);
317 InputEnabled = bEnable;
318 return bOldState;
322 /***********************************************************************
323 * SwapMouseButton (USER.186)
325 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
327 BOOL16 ret = SwappedButtons;
328 SwappedButtons = fSwap;
329 return ret;
333 /***********************************************************************
334 * SwapMouseButton (USER32.@)
336 BOOL WINAPI SwapMouseButton( BOOL fSwap )
338 BOOL ret = SwappedButtons;
339 SwappedButtons = fSwap;
340 return ret;
344 /***********************************************************************
345 * GetCursorPos (USER.17)
347 BOOL16 WINAPI GetCursorPos16( POINT16 *pt )
349 if (!pt) return 0;
350 pt->x = PosX;
351 pt->y = PosY;
352 return 1;
356 /***********************************************************************
357 * GetCursorPos (USER32.@)
359 BOOL WINAPI GetCursorPos( POINT *pt )
361 if (!pt) return 0;
362 pt->x = PosX;
363 pt->y = PosY;
364 return 1;
368 /**********************************************************************
369 * EVENT_Capture
371 * We need this to be able to generate double click messages
372 * when menu code captures mouse in the window without CS_DBLCLK style.
374 HWND EVENT_Capture(HWND hwnd, INT16 ht)
376 HWND capturePrev = 0, captureWnd = 0;
377 MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0;
378 WND* wndPtr = 0;
379 INT16 captureHT = 0;
381 /* Get the messageQ for the current thread */
382 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
384 WARN_(win)("\tCurrent message queue not found. Exiting!\n" );
385 goto CLEANUP;
388 /* Get the current capture window from the perQ data of the current message Q */
389 capturePrev = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
391 if (!hwnd)
393 captureWnd = 0L;
394 captureHT = 0;
396 else
398 wndPtr = WIN_FindWndPtr( hwnd );
399 if (wndPtr)
401 TRACE_(win)("(0x%04x)\n", hwnd );
402 captureWnd = hwnd;
403 captureHT = ht;
407 /* Update the perQ capture window and send messages */
408 if( capturePrev != captureWnd )
410 if (wndPtr)
412 /* Retrieve the message queue associated with this window */
413 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
414 if ( !pMsgQ )
416 WARN_(win)("\tMessage queue not found. Exiting!\n" );
417 goto CLEANUP;
420 /* Make sure that message queue for the window we are setting capture to
421 * shares the same perQ data as the current threads message queue.
423 if ( pCurMsgQ->pQData != pMsgQ->pQData )
424 goto CLEANUP;
427 PERQDATA_SetCaptureWnd( pCurMsgQ->pQData, captureWnd );
428 PERQDATA_SetCaptureInfo( pCurMsgQ->pQData, captureHT );
430 if( capturePrev )
432 WND* xwndPtr = WIN_FindWndPtr( capturePrev );
433 if( xwndPtr && (xwndPtr->flags & WIN_ISWIN32) )
434 SendMessageA( capturePrev, WM_CAPTURECHANGED, 0L, hwnd);
435 WIN_ReleaseWndPtr(xwndPtr);
439 CLEANUP:
440 /* Unlock the queues before returning */
441 if ( pMsgQ )
442 QUEUE_Unlock( pMsgQ );
443 if ( pCurMsgQ )
444 QUEUE_Unlock( pCurMsgQ );
446 WIN_ReleaseWndPtr(wndPtr);
447 return capturePrev;
451 /**********************************************************************
452 * SetCapture (USER.18)
454 HWND16 WINAPI SetCapture16( HWND16 hwnd )
456 return (HWND16)EVENT_Capture( hwnd, HTCLIENT );
460 /**********************************************************************
461 * SetCapture (USER32.@)
463 HWND WINAPI SetCapture( HWND hwnd )
465 return EVENT_Capture( hwnd, HTCLIENT );
469 /**********************************************************************
470 * ReleaseCapture (USER.19) (USER32.@)
472 BOOL WINAPI ReleaseCapture(void)
474 return (EVENT_Capture( 0, 0 ) != 0);
478 /**********************************************************************
479 * GetCapture (USER.236)
481 HWND16 WINAPI GetCapture16(void)
483 return (HWND16)GetCapture();
486 /**********************************************************************
487 * GetCapture (USER32.@)
489 HWND WINAPI GetCapture(void)
491 MESSAGEQUEUE *pCurMsgQ = 0;
492 HWND hwndCapture = 0;
494 /* Get the messageQ for the current thread */
495 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
497 TRACE_(win)("GetCapture: Current message queue not found. Exiting!\n" );
498 return 0;
501 /* Get the current capture window from the perQ data of the current message Q */
502 hwndCapture = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
504 QUEUE_Unlock( pCurMsgQ );
505 return hwndCapture;
508 /**********************************************************************
509 * GetKeyState (USER.106)
511 INT16 WINAPI GetKeyState16(INT16 vkey)
513 return GetKeyState(vkey);
516 /**********************************************************************
517 * GetKeyState (USER32.@)
519 * An application calls the GetKeyState function in response to a
520 * keyboard-input message. This function retrieves the state of the key
521 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
523 SHORT WINAPI GetKeyState(INT vkey)
525 INT retval;
527 switch (vkey)
529 case VK_LBUTTON : /* VK_LBUTTON is 1 */
530 retval = MouseButtonsStates[0] ? 0x8000 : 0;
531 break;
532 case VK_MBUTTON : /* VK_MBUTTON is 4 */
533 retval = MouseButtonsStates[1] ? 0x8000 : 0;
534 break;
535 case VK_RBUTTON : /* VK_RBUTTON is 2 */
536 retval = MouseButtonsStates[2] ? 0x8000 : 0;
537 break;
538 default :
539 if (vkey >= 'a' && vkey <= 'z')
540 vkey += 'A' - 'a';
541 retval = ( (WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
542 (WORD)(QueueKeyStateTable[vkey] & 0x01);
544 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
545 return retval;
548 /**********************************************************************
549 * GetKeyboardState (USER.222) (USER32.@)
551 * An application calls the GetKeyboardState function in response to a
552 * keyboard-input message. This function retrieves the state of the keyboard
553 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
555 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
557 TRACE_(key)("(%p)\n", lpKeyState);
558 if (lpKeyState != NULL) {
559 QueueKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
560 QueueKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
561 QueueKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
562 memcpy(lpKeyState, QueueKeyStateTable, 256);
565 return TRUE;
568 /**********************************************************************
569 * SetKeyboardState (USER.223) (USER32.@)
571 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
573 TRACE_(key)("(%p)\n", lpKeyState);
574 if (lpKeyState != NULL) {
575 memcpy(QueueKeyStateTable, lpKeyState, 256);
576 MouseButtonsStates[0] = (QueueKeyStateTable[VK_LBUTTON] != 0);
577 MouseButtonsStates[1] = (QueueKeyStateTable[VK_MBUTTON] != 0);
578 MouseButtonsStates[2] = (QueueKeyStateTable[VK_RBUTTON] != 0);
581 return TRUE;
584 /**********************************************************************
585 * GetAsyncKeyState (USER32.@)
587 * Determine if a key is or was pressed. retval has high-order
588 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
589 * been pressed.
591 * This uses the variable AsyncMouseButtonsStates and
592 * AsyncKeyStateTable (set in event.c) which have the mouse button
593 * number or key number (whichever is applicable) set to true if the
594 * mouse or key had been depressed since the last call to
595 * GetAsyncKeyState.
597 WORD WINAPI GetAsyncKeyState(INT nKey)
599 short retval;
601 switch (nKey) {
602 case VK_LBUTTON:
603 retval = (AsyncMouseButtonsStates[0] ? 0x0001 : 0) |
604 (MouseButtonsStates[0] ? 0x8000 : 0);
605 break;
606 case VK_MBUTTON:
607 retval = (AsyncMouseButtonsStates[1] ? 0x0001 : 0) |
608 (MouseButtonsStates[1] ? 0x8000 : 0);
609 break;
610 case VK_RBUTTON:
611 retval = (AsyncMouseButtonsStates[2] ? 0x0001 : 0) |
612 (MouseButtonsStates[2] ? 0x8000 : 0);
613 break;
614 default:
615 retval = AsyncKeyStateTable[nKey] |
616 ((InputKeyStateTable[nKey] & 0x80) ? 0x8000 : 0);
617 break;
620 /* all states to false */
621 memset( AsyncMouseButtonsStates, 0, sizeof(AsyncMouseButtonsStates) );
622 memset( AsyncKeyStateTable, 0, sizeof(AsyncKeyStateTable) );
624 TRACE_(key)("(%x) -> %x\n", nKey, retval);
625 return retval;
628 /**********************************************************************
629 * GetAsyncKeyState (USER.249)
631 WORD WINAPI GetAsyncKeyState16(INT16 nKey)
633 return GetAsyncKeyState(nKey);
636 /***********************************************************************
637 * IsUserIdle (USER.333)
639 BOOL16 WINAPI IsUserIdle16(void)
641 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
642 return FALSE;
644 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
645 return FALSE;
647 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
648 return FALSE;
650 /* Should check for screen saver activation here ... */
652 return TRUE;
655 /**********************************************************************
656 * VkKeyScanA (USER32.@)
658 WORD WINAPI VkKeyScanA(CHAR cChar)
660 return VkKeyScan16(cChar);
663 /******************************************************************************
664 * VkKeyScanW (USER32.@)
666 WORD WINAPI VkKeyScanW(WCHAR cChar)
668 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
671 /**********************************************************************
672 * VkKeyScanExA (USER32.@)
674 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
676 /* FIXME: complete workaround this is */
677 return VkKeyScan16(cChar);
680 /******************************************************************************
681 * VkKeyScanExW (USER32.@)
683 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
685 /* FIXME: complete workaround this is */
686 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
689 /******************************************************************************
690 * GetKeyboardType (USER32.@)
692 INT WINAPI GetKeyboardType(INT nTypeFlag)
694 return GetKeyboardType16(nTypeFlag);
697 /******************************************************************************
698 * MapVirtualKeyA (USER32.@)
700 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
702 return MapVirtualKey16(code,maptype);
705 /******************************************************************************
706 * MapVirtualKeyW (USER32.@)
708 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
710 return MapVirtualKey16(code,maptype);
713 /******************************************************************************
714 * MapVirtualKeyExA (USER32.@)
716 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
718 if (hkl)
719 FIXME_(keyboard)("(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
720 return MapVirtualKey16(code,maptype);
723 /******************************************************************************
724 * MapVirtualKeyExW (USER32.@)
726 UINT WINAPI MapVirtualKeyExW(UINT code, UINT maptype, HKL hkl)
728 if (hkl)
729 FIXME_(keyboard)("(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
730 return MapVirtualKey16(code,maptype);
733 /****************************************************************************
734 * GetKBCodePage (USER32.@)
736 UINT WINAPI GetKBCodePage(void)
738 return GetOEMCP();
741 /****************************************************************************
742 * GetKeyboardLayoutName (USER.477)
744 INT16 WINAPI GetKeyboardLayoutName16(LPSTR pwszKLID)
746 return GetKeyboardLayoutNameA(pwszKLID);
749 /***********************************************************************
750 * GetKeyboardLayout (USER32.@)
752 * FIXME: - device handle for keyboard layout defaulted to
753 * the language id. This is the way Windows default works.
754 * - the thread identifier (dwLayout) is also ignored.
756 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
758 HKL layout;
759 layout = GetSystemDefaultLCID(); /* FIXME */
760 layout |= (layout<<16); /* FIXME */
761 TRACE_(keyboard)("returning %08x\n",layout);
762 return layout;
765 /****************************************************************************
766 * GetKeyboardLayoutNameA (USER32.@)
768 INT WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID)
770 sprintf(pwszKLID, "%08x",GetKeyboardLayout(0));
771 return 1;
774 /****************************************************************************
775 * GetKeyboardLayoutNameW (USER32.@)
777 INT WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
779 char buf[KL_NAMELENGTH];
780 int res = GetKeyboardLayoutNameA(buf);
781 MultiByteToWideChar( CP_ACP, 0, buf, -1, pwszKLID, KL_NAMELENGTH );
782 return res;
785 /****************************************************************************
786 * GetKeyNameTextA (USER32.@)
788 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
790 return GetKeyNameText16(lParam,lpBuffer,nSize);
793 /****************************************************************************
794 * GetKeyNameTextW (USER32.@)
796 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
798 int res;
799 LPSTR buf = HeapAlloc( GetProcessHeap(), 0, nSize );
800 if(buf == NULL) return 0; /* FIXME: is this the correct failure value?*/
801 res = GetKeyNameTextA(lParam,buf,nSize);
803 if (nSize > 0 && !MultiByteToWideChar( CP_ACP, 0, buf, -1, lpBuffer, nSize ))
804 lpBuffer[nSize-1] = 0;
805 HeapFree( GetProcessHeap(), 0, buf );
806 return res;
809 /****************************************************************************
810 * ToUnicode (USER32.@)
812 INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
813 LPWSTR lpwStr, int size, UINT flags)
815 return USER_Driver.pToUnicode(virtKey, scanCode, lpKeyState, lpwStr, size, flags);
818 /****************************************************************************
819 * ToUnicodeEx (USER32.@)
821 INT WINAPI ToUnicodeEx(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
822 LPWSTR lpwStr, int size, UINT flags, HKL hkl)
824 /* FIXME: need true implementation */
825 return ToUnicode(virtKey, scanCode, lpKeyState, lpwStr, size, flags);
828 /****************************************************************************
829 * ToAscii (USER32.@)
831 INT WINAPI ToAscii( UINT virtKey,UINT scanCode,LPBYTE lpKeyState,
832 LPWORD lpChar,UINT flags )
834 WCHAR uni_chars[2];
835 INT ret, n_ret;
837 ret = ToUnicode(virtKey, scanCode, lpKeyState, uni_chars, 2, flags);
838 if(ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
839 else n_ret = ret;
840 WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
841 return ret;
844 /****************************************************************************
845 * ToAsciiEx (USER32.@)
847 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
848 LPWORD lpChar, UINT flags, HKL dwhkl )
850 /* FIXME: need true implementation */
851 return ToAscii(virtKey, scanCode, lpKeyState, lpChar, flags);
854 /**********************************************************************
855 * ActivateKeyboardLayout (USER32.@)
857 * Call ignored. WINE supports only system default keyboard layout.
859 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
861 TRACE_(keyboard)("(%d, %d)\n", hLayout, flags);
862 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
863 return 0;
867 /***********************************************************************
868 * GetKeyboardLayoutList (USER32.@)
870 * FIXME: Supports only the system default language and layout and
871 * returns only 1 value.
873 * Return number of values available if either input parm is
874 * 0, per MS documentation.
877 INT WINAPI GetKeyboardLayoutList(INT nBuff,HKL *layouts)
879 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
880 if (!nBuff || !layouts)
881 return 1;
882 if (layouts)
883 layouts[0] = GetKeyboardLayout(0);
884 return 1;
888 /***********************************************************************
889 * RegisterHotKey (USER32.@)
891 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk) {
892 FIXME_(keyboard)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
893 return TRUE;
896 /***********************************************************************
897 * UnregisterHotKey (USER32.@)
899 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id) {
900 FIXME_(keyboard)("(0x%08x,%d): stub\n",hwnd,id);
901 return TRUE;
904 /***********************************************************************
905 * LoadKeyboardLayoutA (USER32.@)
906 * Call ignored. WINE supports only system default keyboard layout.
908 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
910 TRACE_(keyboard)("(%s, %d)\n", pwszKLID, Flags);
911 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
912 return 0;
915 /***********************************************************************
916 * LoadKeyboardLayoutW (USER32.@)
918 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
920 char buf[9];
922 WideCharToMultiByte( CP_ACP, 0, pwszKLID, -1, buf, sizeof(buf), NULL, NULL );
923 buf[8] = 0;
924 return LoadKeyboardLayoutA(buf, Flags);