Use libwine and libwine_unicode directly from their build directory
[wine/multimedia.git] / windows / input.c
blobafa45fa30fc342c44933b537c9f38caf13b1ab21
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 "wingdi.h"
21 #include "winuser.h"
22 #include "wine/winbase16.h"
23 #include "wine/winuser16.h"
24 #include "wine/keyboard16.h"
25 #include "win.h"
26 #include "heap.h"
27 #include "input.h"
28 #include "keyboard.h"
29 #include "mouse.h"
30 #include "message.h"
31 #include "queue.h"
32 #include "debugtools.h"
33 #include "winerror.h"
34 #include "task.h"
36 DECLARE_DEBUG_CHANNEL(event);
37 DECLARE_DEBUG_CHANNEL(key);
38 DECLARE_DEBUG_CHANNEL(keyboard);
39 DECLARE_DEBUG_CHANNEL(win);
41 static BOOL InputEnabled = TRUE;
42 BOOL SwappedButtons = FALSE;
44 BOOL MouseButtonsStates[3];
45 BOOL AsyncMouseButtonsStates[3];
46 BYTE InputKeyStateTable[256];
47 BYTE QueueKeyStateTable[256];
48 BYTE AsyncKeyStateTable[256];
50 /* Storage for the USER-maintained mouse positions */
51 DWORD PosX, PosY;
53 typedef union
55 struct
57 unsigned long count : 16;
58 unsigned long code : 8;
59 unsigned long extended : 1;
60 unsigned long unused : 2;
61 unsigned long win_internal : 2;
62 unsigned long context : 1;
63 unsigned long previous : 1;
64 unsigned long transition : 1;
65 } lp1;
66 unsigned long lp2;
67 } KEYLP;
69 /***********************************************************************
70 * keybd_event (USER32.583)
72 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
73 DWORD dwFlags, DWORD dwExtraInfo )
75 DWORD time, extra;
76 WORD message;
77 KEYLP keylp;
78 keylp.lp2 = 0;
80 if (!InputEnabled) return;
83 * If we are called by the Wine keyboard driver, use the additional
84 * info pointed to by the dwExtraInfo argument.
85 * Otherwise, we need to determine that info ourselves (probably
86 * less accurate, but we can't help that ...).
88 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_KEYBDEVENT) )
89 && ((WINE_KEYBDEVENT *)dwExtraInfo)->magic == WINE_KEYBDEVENT_MAGIC )
91 WINE_KEYBDEVENT *wke = (WINE_KEYBDEVENT *)dwExtraInfo;
92 time = wke->time;
93 extra = 0;
95 else
97 time = GetTickCount();
98 extra = dwExtraInfo;
102 keylp.lp1.count = 1;
103 keylp.lp1.code = bScan;
104 keylp.lp1.extended = (dwFlags & KEYEVENTF_EXTENDEDKEY) != 0;
105 keylp.lp1.win_internal = 0; /* this has something to do with dialogs,
106 * don't remember where I read it - AK */
107 /* it's '1' under windows, when a dialog box appears
108 * and you press one of the underlined keys - DF*/
110 if ( dwFlags & KEYEVENTF_KEYUP )
112 BOOL sysKey = (InputKeyStateTable[VK_MENU] & 0x80)
113 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
114 && !(dwFlags & KEYEVENTF_WINE_FORCEEXTENDED); /* for Alt from AltGr */
116 InputKeyStateTable[bVk] &= ~0x80;
117 keylp.lp1.previous = 1;
118 keylp.lp1.transition = 1;
119 message = sysKey ? WM_SYSKEYUP : WM_KEYUP;
121 else
123 keylp.lp1.previous = (InputKeyStateTable[bVk] & 0x80) != 0;
124 keylp.lp1.transition = 0;
126 if (!(InputKeyStateTable[bVk] & 0x80))
127 InputKeyStateTable[bVk] ^= 0x01;
128 InputKeyStateTable[bVk] |= 0x80;
130 message = (InputKeyStateTable[VK_MENU] & 0x80)
131 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
132 ? WM_SYSKEYDOWN : WM_KEYDOWN;
135 if ( message == WM_SYSKEYDOWN || message == WM_SYSKEYUP )
136 keylp.lp1.context = (InputKeyStateTable[VK_MENU] & 0x80) != 0; /* 1 if alt */
139 TRACE_(key)(" wParam=%04X, lParam=%08lX\n", bVk, keylp.lp2 );
140 TRACE_(key)(" InputKeyState=%X\n", InputKeyStateTable[bVk] );
142 hardware_event( message, bVk, keylp.lp2, PosX, PosY, time, extra );
145 /***********************************************************************
146 * WIN16_keybd_event (USER.289)
148 void WINAPI WIN16_keybd_event( CONTEXT86 *context )
150 DWORD dwFlags = 0;
152 if (AH_reg(context) & 0x80) dwFlags |= KEYEVENTF_KEYUP;
153 if (BH_reg(context) & 1 ) dwFlags |= KEYEVENTF_EXTENDEDKEY;
155 keybd_event( AL_reg(context), BL_reg(context),
156 dwFlags, MAKELONG(SI_reg(context), DI_reg(context)) );
159 /***********************************************************************
160 * mouse_event (USER32.584)
162 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
163 DWORD cButtons, DWORD dwExtraInfo )
165 DWORD time, extra;
166 DWORD keyState;
168 if (!InputEnabled) return;
170 if ( dwFlags & MOUSEEVENTF_MOVE )
172 if ( dwFlags & MOUSEEVENTF_ABSOLUTE )
174 PosX = (dx * GetSystemMetrics(SM_CXSCREEN)) >> 16;
175 PosY = (dy * GetSystemMetrics(SM_CYSCREEN)) >> 16;
177 else
179 int width = GetSystemMetrics(SM_CXSCREEN);
180 int height = GetSystemMetrics(SM_CYSCREEN);
181 long posX = (long) PosX, posY = (long) PosY;
183 /* dx and dy can be negative numbers for relative movements */
184 posX += (long) dx;
185 posY += (long) dy;
187 /* Clip to the current screen size */
188 if (posX < 0) PosX = 0;
189 else if (posX >= width) PosX = width - 1;
190 else PosX = posX;
192 if (posY < 0) PosY = 0;
193 else if (posY >= height) PosY = height - 1;
194 else PosY = posY;
199 * If we are called by the Wine mouse driver, use the additional
200 * info pointed to by the dwExtraInfo argument.
201 * Otherwise, we need to determine that info ourselves (probably
202 * less accurate, but we can't help that ...).
204 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_MOUSEEVENT) )
205 && ((WINE_MOUSEEVENT *)dwExtraInfo)->magic == WINE_MOUSEEVENT_MAGIC )
207 WINE_MOUSEEVENT *wme = (WINE_MOUSEEVENT *)dwExtraInfo;
208 time = wme->time;
209 extra = (DWORD)wme->hWnd;
210 keyState = wme->keyState;
212 if (keyState != GET_KEYSTATE()) {
213 /* We need to update the keystate with what X provides us */
214 MouseButtonsStates[SwappedButtons ? 2 : 0] = (keyState & MK_LBUTTON ? TRUE : FALSE);
215 MouseButtonsStates[SwappedButtons ? 0 : 2] = (keyState & MK_RBUTTON ? TRUE : FALSE);
216 MouseButtonsStates[1] = (keyState & MK_MBUTTON ? TRUE : FALSE);
217 InputKeyStateTable[VK_SHIFT] = (keyState & MK_SHIFT ? 0x80 : 0);
218 InputKeyStateTable[VK_CONTROL] = (keyState & MK_CONTROL ? 0x80 : 0);
221 else
223 time = GetTickCount();
224 extra = dwExtraInfo;
225 keyState = GET_KEYSTATE();
227 if ( dwFlags & MOUSEEVENTF_MOVE )
229 /* We have to actually move the cursor */
230 SetCursorPos( PosX, PosY );
235 if ( dwFlags & MOUSEEVENTF_MOVE )
237 hardware_event( WM_MOUSEMOVE,
238 keyState, 0L, PosX, PosY, time, extra );
240 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN) )
242 MouseButtonsStates[0] = AsyncMouseButtonsStates[0] = TRUE;
243 hardware_event( WM_LBUTTONDOWN,
244 keyState, 0L, PosX, PosY, time, extra );
246 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP) )
248 MouseButtonsStates[0] = FALSE;
249 hardware_event( WM_LBUTTONUP,
250 keyState, 0L, PosX, PosY, time, extra );
252 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN) )
254 MouseButtonsStates[2] = AsyncMouseButtonsStates[2] = TRUE;
255 hardware_event( WM_RBUTTONDOWN,
256 keyState, 0L, PosX, PosY, time, extra );
258 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_LEFTUP) )
260 MouseButtonsStates[2] = FALSE;
261 hardware_event( WM_RBUTTONUP,
262 keyState, 0L, PosX, PosY, time, extra );
264 if ( dwFlags & MOUSEEVENTF_MIDDLEDOWN )
266 MouseButtonsStates[1] = AsyncMouseButtonsStates[1] = TRUE;
267 hardware_event( WM_MBUTTONDOWN,
268 keyState, 0L, PosX, PosY, time, extra );
270 if ( dwFlags & MOUSEEVENTF_MIDDLEUP )
272 MouseButtonsStates[1] = FALSE;
273 hardware_event( WM_MBUTTONUP,
274 keyState, 0L, PosX, PosY, time, extra );
276 if ( dwFlags & MOUSEEVENTF_WHEEL )
278 hardware_event( WM_MOUSEWHEEL,
279 keyState, 0L, PosX, PosY, time, extra );
283 /***********************************************************************
284 * WIN16_mouse_event (USER.299)
286 void WINAPI WIN16_mouse_event( CONTEXT86 *context )
288 mouse_event( AX_reg(context), BX_reg(context), CX_reg(context),
289 DX_reg(context), MAKELONG(SI_reg(context), DI_reg(context)) );
292 /***********************************************************************
293 * GetMouseEventProc (USER.337)
295 FARPROC16 WINAPI GetMouseEventProc16(void)
297 HMODULE16 hmodule = GetModuleHandle16("USER");
298 return GetProcAddress16( hmodule, "mouse_event" );
302 /**********************************************************************
303 * EnableHardwareInput (USER.331)
305 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
307 BOOL16 bOldState = InputEnabled;
308 FIXME_(event)("(%d) - stub\n", bEnable);
309 InputEnabled = bEnable;
310 return bOldState;
314 /***********************************************************************
315 * SwapMouseButton16 (USER.186)
317 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
319 BOOL16 ret = SwappedButtons;
320 SwappedButtons = fSwap;
321 return ret;
325 /***********************************************************************
326 * SwapMouseButton (USER32.537)
328 BOOL WINAPI SwapMouseButton( BOOL fSwap )
330 BOOL ret = SwappedButtons;
331 SwappedButtons = fSwap;
332 return ret;
335 /**********************************************************************
336 * EVENT_Capture
338 * We need this to be able to generate double click messages
339 * when menu code captures mouse in the window without CS_DBLCLK style.
341 HWND EVENT_Capture(HWND hwnd, INT16 ht)
343 HWND capturePrev = 0, captureWnd = 0;
344 MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0;
345 WND* wndPtr = 0;
346 INT16 captureHT = 0;
348 /* Get the messageQ for the current thread */
349 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
351 WARN_(win)("\tCurrent message queue not found. Exiting!\n" );
352 goto CLEANUP;
355 /* Get the current capture window from the perQ data of the current message Q */
356 capturePrev = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
358 if (!hwnd)
360 captureWnd = 0L;
361 captureHT = 0;
363 else
365 wndPtr = WIN_FindWndPtr( hwnd );
366 if (wndPtr)
368 TRACE_(win)("(0x%04x)\n", hwnd );
369 captureWnd = hwnd;
370 captureHT = ht;
374 /* Update the perQ capture window and send messages */
375 if( capturePrev != captureWnd )
377 if (wndPtr)
379 /* Retrieve the message queue associated with this window */
380 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
381 if ( !pMsgQ )
383 WARN_(win)("\tMessage queue not found. Exiting!\n" );
384 goto CLEANUP;
387 /* Make sure that message queue for the window we are setting capture to
388 * shares the same perQ data as the current threads message queue.
390 if ( pCurMsgQ->pQData != pMsgQ->pQData )
391 goto CLEANUP;
394 PERQDATA_SetCaptureWnd( pCurMsgQ->pQData, captureWnd );
395 PERQDATA_SetCaptureInfo( pCurMsgQ->pQData, captureHT );
397 if( capturePrev )
399 WND* xwndPtr = WIN_FindWndPtr( capturePrev );
400 if( xwndPtr && (xwndPtr->flags & WIN_ISWIN32) )
401 SendMessageA( capturePrev, WM_CAPTURECHANGED, 0L, hwnd);
402 WIN_ReleaseWndPtr(xwndPtr);
406 CLEANUP:
407 /* Unlock the queues before returning */
408 if ( pMsgQ )
409 QUEUE_Unlock( pMsgQ );
410 if ( pCurMsgQ )
411 QUEUE_Unlock( pCurMsgQ );
413 WIN_ReleaseWndPtr(wndPtr);
414 return capturePrev;
418 /**********************************************************************
419 * SetCapture16 (USER.18)
421 HWND16 WINAPI SetCapture16( HWND16 hwnd )
423 return (HWND16)EVENT_Capture( hwnd, HTCLIENT );
427 /**********************************************************************
428 * SetCapture (USER32.464)
430 HWND WINAPI SetCapture( HWND hwnd )
432 return EVENT_Capture( hwnd, HTCLIENT );
436 /**********************************************************************
437 * ReleaseCapture (USER.19) (USER32.439)
439 BOOL WINAPI ReleaseCapture(void)
441 return (EVENT_Capture( 0, 0 ) != 0);
445 /**********************************************************************
446 * GetCapture16 (USER.236)
448 HWND16 WINAPI GetCapture16(void)
450 return (HWND16)GetCapture();
453 /**********************************************************************
454 * GetCapture (USER32.208)
456 HWND WINAPI GetCapture(void)
458 MESSAGEQUEUE *pCurMsgQ = 0;
459 HWND hwndCapture = 0;
461 /* Get the messageQ for the current thread */
462 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
464 TRACE_(win)("GetCapture: Current message queue not found. Exiting!\n" );
465 return 0;
468 /* Get the current capture window from the perQ data of the current message Q */
469 hwndCapture = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
471 QUEUE_Unlock( pCurMsgQ );
472 return hwndCapture;
475 /**********************************************************************
476 * GetKeyState (USER.106)
478 INT16 WINAPI GetKeyState16(INT16 vkey)
480 return GetKeyState(vkey);
483 /**********************************************************************
484 * GetKeyState (USER32.249)
486 * An application calls the GetKeyState function in response to a
487 * keyboard-input message. This function retrieves the state of the key
488 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
490 SHORT WINAPI GetKeyState(INT vkey)
492 INT retval;
494 switch (vkey)
496 case VK_LBUTTON : /* VK_LBUTTON is 1 */
497 retval = MouseButtonsStates[0] ? 0x8000 : 0;
498 break;
499 case VK_MBUTTON : /* VK_MBUTTON is 4 */
500 retval = MouseButtonsStates[1] ? 0x8000 : 0;
501 break;
502 case VK_RBUTTON : /* VK_RBUTTON is 2 */
503 retval = MouseButtonsStates[2] ? 0x8000 : 0;
504 break;
505 default :
506 if (vkey >= 'a' && vkey <= 'z')
507 vkey += 'A' - 'a';
508 retval = ( (WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
509 (WORD)(QueueKeyStateTable[vkey] & 0x01);
511 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
512 return retval;
515 /**********************************************************************
516 * GetKeyboardState (USER.222)(USER32.254)
518 * An application calls the GetKeyboardState function in response to a
519 * keyboard-input message. This function retrieves the state of the keyboard
520 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
522 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
524 TRACE_(key)("(%p)\n", lpKeyState);
525 if (lpKeyState != NULL) {
526 QueueKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
527 QueueKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
528 QueueKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
529 memcpy(lpKeyState, QueueKeyStateTable, 256);
532 return TRUE;
535 /**********************************************************************
536 * SetKeyboardState (USER.223)(USER32.484)
538 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
540 TRACE_(key)("(%p)\n", lpKeyState);
541 if (lpKeyState != NULL) {
542 memcpy(QueueKeyStateTable, lpKeyState, 256);
543 MouseButtonsStates[0] = (QueueKeyStateTable[VK_LBUTTON] != 0);
544 MouseButtonsStates[1] = (QueueKeyStateTable[VK_MBUTTON] != 0);
545 MouseButtonsStates[2] = (QueueKeyStateTable[VK_RBUTTON] != 0);
548 return TRUE;
551 /**********************************************************************
552 * GetAsyncKeyState (USER32.207)
554 * Determine if a key is or was pressed. retval has high-order
555 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
556 * been pressed.
558 * This uses the variable AsyncMouseButtonsStates and
559 * AsyncKeyStateTable (set in event.c) which have the mouse button
560 * number or key number (whichever is applicable) set to true if the
561 * mouse or key had been depressed since the last call to
562 * GetAsyncKeyState.
564 WORD WINAPI GetAsyncKeyState(INT nKey)
566 short retval;
568 switch (nKey) {
569 case VK_LBUTTON:
570 retval = (AsyncMouseButtonsStates[0] ? 0x0001 : 0) |
571 (MouseButtonsStates[0] ? 0x8000 : 0);
572 break;
573 case VK_MBUTTON:
574 retval = (AsyncMouseButtonsStates[1] ? 0x0001 : 0) |
575 (MouseButtonsStates[1] ? 0x8000 : 0);
576 break;
577 case VK_RBUTTON:
578 retval = (AsyncMouseButtonsStates[2] ? 0x0001 : 0) |
579 (MouseButtonsStates[2] ? 0x8000 : 0);
580 break;
581 default:
582 retval = AsyncKeyStateTable[nKey] |
583 ((InputKeyStateTable[nKey] & 0x80) ? 0x8000 : 0);
584 break;
587 /* all states to false */
588 memset( AsyncMouseButtonsStates, 0, sizeof(AsyncMouseButtonsStates) );
589 memset( AsyncKeyStateTable, 0, sizeof(AsyncKeyStateTable) );
591 TRACE_(key)("(%x) -> %x\n", nKey, retval);
592 return retval;
595 /**********************************************************************
596 * GetAsyncKeyState16 (USER.249)
598 WORD WINAPI GetAsyncKeyState16(INT16 nKey)
600 return GetAsyncKeyState(nKey);
603 /***********************************************************************
604 * IsUserIdle (USER.333)
606 BOOL16 WINAPI IsUserIdle16(void)
608 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
609 return FALSE;
611 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
612 return FALSE;
614 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
615 return FALSE;
617 /* Should check for screen saver activation here ... */
619 return TRUE;
622 /**********************************************************************
623 * VkKeyScanA (USER32.573)
625 WORD WINAPI VkKeyScanA(CHAR cChar)
627 return VkKeyScan16(cChar);
630 /******************************************************************************
631 * VkKeyScanW (USER32.576)
633 WORD WINAPI VkKeyScanW(WCHAR cChar)
635 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
638 /**********************************************************************
639 * VkKeyScanExA (USER32.574)
641 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
643 /* FIXME: complete workaround this is */
644 return VkKeyScan16(cChar);
647 /******************************************************************************
648 * VkKeyScanExW (USER32.575)
650 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
652 /* FIXME: complete workaround this is */
653 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
656 /******************************************************************************
657 * GetKeyboardType (USER32.255)
659 INT WINAPI GetKeyboardType(INT nTypeFlag)
661 return GetKeyboardType16(nTypeFlag);
664 /******************************************************************************
665 * MapVirtualKeyA (USER32.383)
667 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
669 return MapVirtualKey16(code,maptype);
672 /******************************************************************************
673 * MapVirtualKeyW (USER32.385)
675 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
677 return MapVirtualKey16(code,maptype);
680 /******************************************************************************
681 * MapVirtualKeyExA (USER32.384)
683 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
685 if (hkl)
686 FIXME_(keyboard)("(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
687 return MapVirtualKey16(code,maptype);
690 /******************************************************************************
691 * MapVirtualKeyExW (USER32.???)
693 UINT WINAPI MapVirtualKeyExW(UINT code, UINT maptype, HKL hkl)
695 if (hkl)
696 FIXME_(keyboard)("(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
697 return MapVirtualKey16(code,maptype);
700 /****************************************************************************
701 * GetKBCodePage (USER32.246)
703 UINT WINAPI GetKBCodePage(void)
705 return GetKBCodePage16();
708 /****************************************************************************
709 * GetKeyboardLayoutName16 (USER.477)
711 INT16 WINAPI GetKeyboardLayoutName16(LPSTR pwszKLID)
713 return GetKeyboardLayoutNameA(pwszKLID);
716 /***********************************************************************
717 * GetKeyboardLayout (USER32.250)
719 * FIXME: - device handle for keyboard layout defaulted to
720 * the language id. This is the way Windows default works.
721 * - the thread identifier (dwLayout) is also ignored.
723 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
725 HKL layout;
726 layout = GetSystemDefaultLCID(); /* FIXME */
727 layout |= (layout<<16); /* FIXME */
728 TRACE_(keyboard)("returning %08x\n",layout);
729 return layout;
732 /****************************************************************************
733 * GetKeyboardLayoutNameA (USER32.252)
735 INT WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID)
737 sprintf(pwszKLID, "%08x",GetKeyboardLayout(0));
738 return 1;
741 /****************************************************************************
742 * GetKeyboardLayoutNameW (USER32.253)
744 INT WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
746 char buf[KL_NAMELENGTH];
747 int res = GetKeyboardLayoutNameA(buf);
748 MultiByteToWideChar( CP_ACP, 0, buf, -1, pwszKLID, KL_NAMELENGTH );
749 return res;
752 /****************************************************************************
753 * GetKeyNameTextA (USER32.247)
755 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
757 return GetKeyNameText16(lParam,lpBuffer,nSize);
760 /****************************************************************************
761 * GetKeyNameTextW (USER32.248)
763 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
765 int res;
766 LPSTR buf = HeapAlloc( GetProcessHeap(), 0, nSize );
767 if(buf == NULL) return 0; /* FIXME: is this the correct failure value?*/
768 res = GetKeyNameTextA(lParam,buf,nSize);
770 if (nSize > 0 && !MultiByteToWideChar( CP_ACP, 0, buf, -1, lpBuffer, nSize ))
771 lpBuffer[nSize-1] = 0;
772 HeapFree( GetProcessHeap(), 0, buf );
773 return res;
776 /****************************************************************************
777 * ToUnicode (USER32.@)
779 INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
780 LPWSTR lpwStr, int size, UINT flags)
782 return USER_Driver.pToUnicode(virtKey, scanCode, lpKeyState, lpwStr, size, flags);
785 /****************************************************************************
786 * ToUnicodeEx (USER32.@)
788 INT WINAPI ToUnicodeEx(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
789 LPWSTR lpwStr, int size, UINT flags, HKL hkl)
791 /* FIXME: need true implementation */
792 return ToUnicode(virtKey, scanCode, lpKeyState, lpwStr, size, flags);
795 /****************************************************************************
796 * ToAscii (USER32.546)
798 INT WINAPI ToAscii( UINT virtKey,UINT scanCode,LPBYTE lpKeyState,
799 LPWORD lpChar,UINT flags )
801 WCHAR uni_chars[2];
802 INT ret, n_ret;
804 ret = ToUnicode(virtKey, scanCode, lpKeyState, uni_chars, 2, flags);
805 if(ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
806 else n_ret = ret;
807 WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
808 return ret;
811 /****************************************************************************
812 * ToAsciiEx (USER32.547)
814 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
815 LPWORD lpChar, UINT flags, HKL dwhkl )
817 /* FIXME: need true implementation */
818 return ToAscii(virtKey, scanCode, lpKeyState, lpChar, flags);
821 /**********************************************************************
822 * ActivateKeyboardLayout (USER32.1)
824 * Call ignored. WINE supports only system default keyboard layout.
826 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
828 TRACE_(keyboard)("(%d, %d)\n", hLayout, flags);
829 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
830 return 0;
834 /***********************************************************************
835 * GetKeyboardLayoutList (USER32.251)
837 * FIXME: Supports only the system default language and layout and
838 * returns only 1 value.
840 * Return number of values available if either input parm is
841 * 0, per MS documentation.
844 INT WINAPI GetKeyboardLayoutList(INT nBuff,HKL *layouts)
846 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
847 if (!nBuff || !layouts)
848 return 1;
849 if (layouts)
850 layouts[0] = GetKeyboardLayout(0);
851 return 1;
855 /***********************************************************************
856 * RegisterHotKey (USER32.433)
858 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk) {
859 FIXME_(keyboard)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
860 return TRUE;
863 /***********************************************************************
864 * UnregisterHotKey (USER32.565)
866 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id) {
867 FIXME_(keyboard)("(0x%08x,%d): stub\n",hwnd,id);
868 return TRUE;
871 /***********************************************************************
872 * LoadKeyboardLayoutA (USER32.367)
873 * Call ignored. WINE supports only system default keyboard layout.
875 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
877 TRACE_(keyboard)("(%s, %d)\n", pwszKLID, Flags);
878 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
879 return 0;
882 /***********************************************************************
883 * LoadKeyboardLayoutW (USER32.368)
885 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
887 char buf[9];
889 WideCharToMultiByte( CP_ACP, 0, pwszKLID, -1, buf, sizeof(buf), NULL, NULL );
890 buf[8] = 0;
891 return LoadKeyboardLayoutA(buf, Flags);