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
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
38 #define WIN32_NO_STATUS
47 #include "user_private.h"
48 #include "wine/server.h"
49 #include "wine/debug.h"
50 #include "wine/unicode.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(win
);
53 WINE_DECLARE_DEBUG_CHANNEL(keyboard
);
56 /***********************************************************************
59 static WORD
get_key_state(void)
63 if (GetSystemMetrics( SM_SWAPBUTTON
))
65 if (GetAsyncKeyState(VK_RBUTTON
) & 0x80) ret
|= MK_LBUTTON
;
66 if (GetAsyncKeyState(VK_LBUTTON
) & 0x80) ret
|= MK_RBUTTON
;
70 if (GetAsyncKeyState(VK_LBUTTON
) & 0x80) ret
|= MK_LBUTTON
;
71 if (GetAsyncKeyState(VK_RBUTTON
) & 0x80) ret
|= MK_RBUTTON
;
73 if (GetAsyncKeyState(VK_MBUTTON
) & 0x80) ret
|= MK_MBUTTON
;
74 if (GetAsyncKeyState(VK_SHIFT
) & 0x80) ret
|= MK_SHIFT
;
75 if (GetAsyncKeyState(VK_CONTROL
) & 0x80) ret
|= MK_CONTROL
;
76 if (GetAsyncKeyState(VK_XBUTTON1
) & 0x80) ret
|= MK_XBUTTON1
;
77 if (GetAsyncKeyState(VK_XBUTTON2
) & 0x80) ret
|= MK_XBUTTON2
;
82 /**********************************************************************
85 BOOL
set_capture_window( HWND hwnd
, UINT gui_flags
, HWND
*prev_ret
)
91 if (gui_flags
& GUI_INMENUMODE
) flags
|= CAPTURE_MENU
;
92 if (gui_flags
& GUI_INMOVESIZE
) flags
|= CAPTURE_MOVESIZE
;
94 SERVER_START_REQ( set_capture_window
)
96 req
->handle
= wine_server_user_handle( hwnd
);
98 if ((ret
= !wine_server_call_err( req
)))
100 previous
= wine_server_ptr_handle( reply
->previous
);
101 hwnd
= wine_server_ptr_handle( reply
->full_handle
);
108 USER_Driver
->pSetCapture( hwnd
, gui_flags
);
110 if (previous
&& previous
!= hwnd
)
111 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
113 if (prev_ret
) *prev_ret
= previous
;
119 /***********************************************************************
120 * __wine_send_input (USER32.@)
122 * Internal SendInput function to allow the graphics driver to inject real events.
124 BOOL CDECL
__wine_send_input( HWND hwnd
, const INPUT
*input
)
126 NTSTATUS status
= send_hardware_message( hwnd
, input
, 0 );
127 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
132 /***********************************************************************
133 * update_mouse_coords
135 * Helper for SendInput.
137 static void update_mouse_coords( INPUT
*input
)
139 if (!(input
->u
.mi
.dwFlags
& MOUSEEVENTF_MOVE
)) return;
141 if (input
->u
.mi
.dwFlags
& MOUSEEVENTF_ABSOLUTE
)
143 input
->u
.mi
.dx
= (input
->u
.mi
.dx
* GetSystemMetrics( SM_CXSCREEN
)) >> 16;
144 input
->u
.mi
.dy
= (input
->u
.mi
.dy
* GetSystemMetrics( SM_CYSCREEN
)) >> 16;
150 /* dx and dy can be negative numbers for relative movements */
151 SystemParametersInfoW(SPI_GETMOUSE
, 0, accel
, 0);
153 if (!accel
[2]) return;
155 if (abs(input
->u
.mi
.dx
) > accel
[0])
158 if ((abs(input
->u
.mi
.dx
) > accel
[1]) && (accel
[2] == 2)) input
->u
.mi
.dx
*= 2;
160 if (abs(input
->u
.mi
.dy
) > accel
[0])
163 if ((abs(input
->u
.mi
.dy
) > accel
[1]) && (accel
[2] == 2)) input
->u
.mi
.dy
*= 2;
168 /***********************************************************************
169 * SendInput (USER32.@)
171 UINT WINAPI
SendInput( UINT count
, LPINPUT inputs
, int size
)
176 for (i
= 0; i
< count
; i
++)
178 if (inputs
[i
].type
== INPUT_MOUSE
)
180 /* we need to update the coordinates to what the server expects */
181 INPUT input
= inputs
[i
];
182 update_mouse_coords( &input
);
183 status
= send_hardware_message( 0, &input
, SEND_HWMSG_INJECTED
);
185 else status
= send_hardware_message( 0, &inputs
[i
], SEND_HWMSG_INJECTED
);
189 SetLastError( RtlNtStatusToDosError(status
) );
198 /***********************************************************************
199 * keybd_event (USER32.@)
201 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
202 DWORD dwFlags
, ULONG_PTR dwExtraInfo
)
206 input
.type
= INPUT_KEYBOARD
;
207 input
.u
.ki
.wVk
= bVk
;
208 input
.u
.ki
.wScan
= bScan
;
209 input
.u
.ki
.dwFlags
= dwFlags
;
211 input
.u
.ki
.dwExtraInfo
= dwExtraInfo
;
212 SendInput( 1, &input
, sizeof(input
) );
216 /***********************************************************************
217 * mouse_event (USER32.@)
219 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
220 DWORD dwData
, ULONG_PTR dwExtraInfo
)
224 input
.type
= INPUT_MOUSE
;
227 input
.u
.mi
.mouseData
= dwData
;
228 input
.u
.mi
.dwFlags
= dwFlags
;
230 input
.u
.mi
.dwExtraInfo
= dwExtraInfo
;
231 SendInput( 1, &input
, sizeof(input
) );
235 /***********************************************************************
236 * GetCursorPos (USER32.@)
238 BOOL WINAPI DECLSPEC_HOTPATCH
GetCursorPos( POINT
*pt
)
243 if (!pt
) return FALSE
;
245 SERVER_START_REQ( set_cursor
)
247 if ((ret
= !wine_server_call( req
)))
249 pt
->x
= reply
->new_x
;
250 pt
->y
= reply
->new_y
;
251 last_change
= reply
->last_change
;
256 /* query new position from graphics driver if we haven't updated recently */
257 if (ret
&& GetTickCount() - last_change
> 100) ret
= USER_Driver
->pGetCursorPos( pt
);
262 /***********************************************************************
263 * GetCursorInfo (USER32.@)
265 BOOL WINAPI
GetCursorInfo( PCURSORINFO pci
)
271 SERVER_START_REQ( get_thread_input
)
274 if ((ret
= !wine_server_call( req
)))
276 pci
->hCursor
= wine_server_ptr_handle( reply
->cursor
);
277 pci
->flags
= (reply
->show_count
>= 0) ? CURSOR_SHOWING
: 0;
281 GetCursorPos(&pci
->ptScreenPos
);
286 /***********************************************************************
287 * SetCursorPos (USER32.@)
289 BOOL WINAPI DECLSPEC_HOTPATCH
SetCursorPos( INT x
, INT y
)
292 INT prev_x
, prev_y
, new_x
, new_y
;
294 SERVER_START_REQ( set_cursor
)
296 req
->flags
= SET_CURSOR_POS
;
299 if ((ret
= !wine_server_call( req
)))
301 prev_x
= reply
->prev_x
;
302 prev_y
= reply
->prev_y
;
303 new_x
= reply
->new_x
;
304 new_y
= reply
->new_y
;
308 if (ret
&& (prev_x
!= new_x
|| prev_y
!= new_y
)) USER_Driver
->pSetCursorPos( new_x
, new_y
);
313 /**********************************************************************
314 * SetCapture (USER32.@)
316 HWND WINAPI DECLSPEC_HOTPATCH
SetCapture( HWND hwnd
)
320 set_capture_window( hwnd
, 0, &previous
);
325 /**********************************************************************
326 * ReleaseCapture (USER32.@)
328 BOOL WINAPI DECLSPEC_HOTPATCH
ReleaseCapture(void)
330 BOOL ret
= set_capture_window( 0, 0, NULL
);
332 /* Somebody may have missed some mouse movements */
333 if (ret
) mouse_event( MOUSEEVENTF_MOVE
, 0, 0, 0, 0 );
339 /**********************************************************************
340 * GetCapture (USER32.@)
342 HWND WINAPI
GetCapture(void)
346 SERVER_START_REQ( get_thread_input
)
348 req
->tid
= GetCurrentThreadId();
349 if (!wine_server_call_err( req
)) ret
= wine_server_ptr_handle( reply
->capture
);
356 /**********************************************************************
357 * GetAsyncKeyState (USER32.@)
359 * Determine if a key is or was pressed. retval has high-order
360 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
363 SHORT WINAPI DECLSPEC_HOTPATCH
GetAsyncKeyState( INT key
)
365 struct user_thread_info
*thread_info
= get_user_thread_info();
368 if (key
< 0 || key
>= 256) return 0;
370 if ((ret
= USER_Driver
->pGetAsyncKeyState( key
)) == -1)
372 if (thread_info
->key_state
&&
373 !(thread_info
->key_state
[key
] & 0xc0) &&
374 GetTickCount() - thread_info
->key_state_time
< 50)
377 if (!thread_info
->key_state
) thread_info
->key_state
= HeapAlloc( GetProcessHeap(), 0, 256 );
380 SERVER_START_REQ( get_key_state
)
384 if (thread_info
->key_state
) wine_server_set_reply( req
, thread_info
->key_state
, 256 );
385 if (!wine_server_call( req
))
387 if (reply
->state
& 0x40) ret
|= 0x0001;
388 if (reply
->state
& 0x80) ret
|= 0x8000;
389 thread_info
->key_state_time
= GetTickCount();
398 /***********************************************************************
399 * GetQueueStatus (USER32.@)
401 DWORD WINAPI
GetQueueStatus( UINT flags
)
405 if (flags
& ~(QS_ALLINPUT
| QS_ALLPOSTMESSAGE
| QS_SMRESULT
))
407 SetLastError( ERROR_INVALID_FLAGS
);
411 /* check for pending X events */
412 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, flags
, 0 );
414 SERVER_START_REQ( get_queue_status
)
417 wine_server_call( req
);
418 ret
= MAKELONG( reply
->changed_bits
& flags
, reply
->wake_bits
& flags
);
425 /***********************************************************************
426 * GetInputState (USER32.@)
428 BOOL WINAPI
GetInputState(void)
432 /* check for pending X events */
433 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_INPUT
, 0 );
435 SERVER_START_REQ( get_queue_status
)
438 wine_server_call( req
);
439 ret
= reply
->wake_bits
& (QS_KEY
| QS_MOUSEBUTTON
);
446 /******************************************************************
447 * GetLastInputInfo (USER32.@)
449 BOOL WINAPI
GetLastInputInfo(PLASTINPUTINFO plii
)
455 if (plii
->cbSize
!= sizeof (*plii
) )
457 SetLastError(ERROR_INVALID_PARAMETER
);
461 SERVER_START_REQ( get_last_input_time
)
463 ret
= !wine_server_call_err( req
);
465 plii
->dwTime
= reply
->time
;
472 /******************************************************************
473 * GetRawInputDeviceList (USER32.@)
475 UINT WINAPI
GetRawInputDeviceList(PRAWINPUTDEVICELIST pRawInputDeviceList
, PUINT puiNumDevices
, UINT cbSize
)
477 FIXME("(pRawInputDeviceList=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDeviceList
, puiNumDevices
, cbSize
);
479 if(pRawInputDeviceList
)
480 memset(pRawInputDeviceList
, 0, sizeof *pRawInputDeviceList
);
486 /******************************************************************
487 * RegisterRawInputDevices (USER32.@)
489 BOOL WINAPI DECLSPEC_HOTPATCH
RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices
, UINT uiNumDevices
, UINT cbSize
)
491 FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices
, uiNumDevices
, cbSize
);
497 /******************************************************************
498 * GetRawInputData (USER32.@)
500 UINT WINAPI
GetRawInputData(HRAWINPUT hRawInput
, UINT uiCommand
, LPVOID pData
, PUINT pcbSize
, UINT cbSizeHeader
)
502 FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n",
503 hRawInput
, uiCommand
, pData
, pcbSize
, cbSizeHeader
);
509 /******************************************************************
510 * GetRawInputBuffer (USER32.@)
512 UINT WINAPI DECLSPEC_HOTPATCH
GetRawInputBuffer(PRAWINPUT pData
, PUINT pcbSize
, UINT cbSizeHeader
)
514 FIXME("(pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n", pData
, pcbSize
, cbSizeHeader
);
520 /******************************************************************
521 * GetRawInputDeviceInfoA (USER32.@)
523 UINT WINAPI
GetRawInputDeviceInfoA(HANDLE hDevice
, UINT uiCommand
, LPVOID pData
, PUINT pcbSize
)
525 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice
, uiCommand
, pData
, pcbSize
);
531 /******************************************************************
532 * GetRawInputDeviceInfoW (USER32.@)
534 UINT WINAPI
GetRawInputDeviceInfoW(HANDLE hDevice
, UINT uiCommand
, LPVOID pData
, PUINT pcbSize
)
536 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice
, uiCommand
, pData
, pcbSize
);
542 /******************************************************************
543 * GetRegisteredRawInputDevices (USER32.@)
545 UINT WINAPI
GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices
, PUINT puiNumDevices
, UINT cbSize
)
547 FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices
, puiNumDevices
, cbSize
);
553 /******************************************************************
554 * DefRawInputProc (USER32.@)
556 LRESULT WINAPI
DefRawInputProc(PRAWINPUT
*paRawInput
, INT nInput
, UINT cbSizeHeader
)
558 FIXME("(paRawInput=%p, nInput=%d, cbSizeHeader=%d) stub!\n", *paRawInput
, nInput
, cbSizeHeader
);
564 /**********************************************************************
565 * AttachThreadInput (USER32.@)
567 * Attaches the input processing mechanism of one thread to that of
570 BOOL WINAPI
AttachThreadInput( DWORD from
, DWORD to
, BOOL attach
)
574 SERVER_START_REQ( attach_thread_input
)
576 req
->tid_from
= from
;
578 req
->attach
= attach
;
579 ret
= !wine_server_call_err( req
);
586 /**********************************************************************
587 * GetKeyState (USER32.@)
589 * An application calls the GetKeyState function in response to a
590 * keyboard-input message. This function retrieves the state of the key
591 * at the time the input message was generated.
593 SHORT WINAPI DECLSPEC_HOTPATCH
GetKeyState(INT vkey
)
597 SERVER_START_REQ( get_key_state
)
599 req
->tid
= GetCurrentThreadId();
601 if (!wine_server_call( req
)) retval
= (signed char)reply
->state
;
604 TRACE("key (0x%x) -> %x\n", vkey
, retval
);
609 /**********************************************************************
610 * GetKeyboardState (USER32.@)
612 BOOL WINAPI DECLSPEC_HOTPATCH
GetKeyboardState( LPBYTE state
)
616 TRACE("(%p)\n", state
);
618 memset( state
, 0, 256 );
619 SERVER_START_REQ( get_key_state
)
621 req
->tid
= GetCurrentThreadId();
623 wine_server_set_reply( req
, state
, 256 );
624 ret
= !wine_server_call_err( req
);
631 /**********************************************************************
632 * SetKeyboardState (USER32.@)
634 BOOL WINAPI
SetKeyboardState( LPBYTE state
)
638 SERVER_START_REQ( set_key_state
)
640 req
->tid
= GetCurrentThreadId();
641 wine_server_add_data( req
, state
, 256 );
642 ret
= !wine_server_call_err( req
);
649 /**********************************************************************
650 * VkKeyScanA (USER32.@)
652 * VkKeyScan translates an ANSI character to a virtual-key and shift code
653 * for the current keyboard.
654 * high-order byte yields :
658 * 3-5 Shift-key combinations that are not used for characters
661 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
662 * FIXME : works ok except for dead chars :
663 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
664 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
666 SHORT WINAPI
VkKeyScanA(CHAR cChar
)
670 if (IsDBCSLeadByte(cChar
)) return -1;
672 MultiByteToWideChar(CP_ACP
, 0, &cChar
, 1, &wChar
, 1);
673 return VkKeyScanW(wChar
);
676 /******************************************************************************
677 * VkKeyScanW (USER32.@)
679 SHORT WINAPI
VkKeyScanW(WCHAR cChar
)
681 return VkKeyScanExW(cChar
, GetKeyboardLayout(0));
684 /**********************************************************************
685 * VkKeyScanExA (USER32.@)
687 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
691 if (IsDBCSLeadByte(cChar
)) return -1;
693 MultiByteToWideChar(CP_ACP
, 0, &cChar
, 1, &wChar
, 1);
694 return VkKeyScanExW(wChar
, dwhkl
);
697 /******************************************************************************
698 * VkKeyScanExW (USER32.@)
700 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
702 return USER_Driver
->pVkKeyScanEx(cChar
, dwhkl
);
705 /**********************************************************************
706 * OemKeyScan (USER32.@)
708 DWORD WINAPI
OemKeyScan(WORD wOemChar
)
713 /******************************************************************************
714 * GetKeyboardType (USER32.@)
716 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
718 TRACE_(keyboard
)("(%d)\n", nTypeFlag
);
721 case 0: /* Keyboard type */
722 return 4; /* AT-101 */
723 case 1: /* Keyboard Subtype */
724 return 0; /* There are no defined subtypes */
725 case 2: /* Number of F-keys */
726 return 12; /* We're doing an 101 for now, so return 12 F-keys */
728 WARN_(keyboard
)("Unknown type\n");
729 return 0; /* The book says 0 here, so 0 */
733 /******************************************************************************
734 * MapVirtualKeyA (USER32.@)
736 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
738 return MapVirtualKeyExA( code
, maptype
, GetKeyboardLayout(0) );
741 /******************************************************************************
742 * MapVirtualKeyW (USER32.@)
744 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
746 return MapVirtualKeyExW(code
, maptype
, GetKeyboardLayout(0));
749 /******************************************************************************
750 * MapVirtualKeyExA (USER32.@)
752 UINT WINAPI
MapVirtualKeyExA(UINT code
, UINT maptype
, HKL hkl
)
756 ret
= MapVirtualKeyExW( code
, maptype
, hkl
);
757 if (maptype
== MAPVK_VK_TO_CHAR
)
762 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, (LPSTR
)&ch
, 1, NULL
, NULL
);
768 /******************************************************************************
769 * MapVirtualKeyExW (USER32.@)
771 UINT WINAPI
MapVirtualKeyExW(UINT code
, UINT maptype
, HKL hkl
)
773 TRACE_(keyboard
)("(%X, %d, %p)\n", code
, maptype
, hkl
);
775 return USER_Driver
->pMapVirtualKeyEx(code
, maptype
, hkl
);
778 /****************************************************************************
779 * GetKBCodePage (USER32.@)
781 UINT WINAPI
GetKBCodePage(void)
786 /***********************************************************************
787 * GetKeyboardLayout (USER32.@)
789 * - device handle for keyboard layout defaulted to
790 * the language id. This is the way Windows default works.
791 * - the thread identifier is also ignored.
793 HKL WINAPI
GetKeyboardLayout(DWORD thread_id
)
795 return USER_Driver
->pGetKeyboardLayout(thread_id
);
798 /****************************************************************************
799 * GetKeyboardLayoutNameA (USER32.@)
801 BOOL WINAPI
GetKeyboardLayoutNameA(LPSTR pszKLID
)
803 WCHAR buf
[KL_NAMELENGTH
];
805 if (GetKeyboardLayoutNameW(buf
))
806 return WideCharToMultiByte( CP_ACP
, 0, buf
, -1, pszKLID
, KL_NAMELENGTH
, NULL
, NULL
) != 0;
810 /****************************************************************************
811 * GetKeyboardLayoutNameW (USER32.@)
813 BOOL WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
815 return USER_Driver
->pGetKeyboardLayoutName(pwszKLID
);
818 /****************************************************************************
819 * GetKeyNameTextA (USER32.@)
821 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
826 if (!nSize
|| !GetKeyNameTextW(lParam
, buf
, 256))
831 ret
= WideCharToMultiByte(CP_ACP
, 0, buf
, -1, lpBuffer
, nSize
, NULL
, NULL
);
842 /****************************************************************************
843 * GetKeyNameTextW (USER32.@)
845 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
847 if (!lpBuffer
|| !nSize
) return 0;
848 return USER_Driver
->pGetKeyNameText( lParam
, lpBuffer
, nSize
);
851 /****************************************************************************
852 * ToUnicode (USER32.@)
854 INT WINAPI
ToUnicode(UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
855 LPWSTR lpwStr
, int size
, UINT flags
)
857 return ToUnicodeEx(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
, GetKeyboardLayout(0));
860 /****************************************************************************
861 * ToUnicodeEx (USER32.@)
863 INT WINAPI
ToUnicodeEx(UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
864 LPWSTR lpwStr
, int size
, UINT flags
, HKL hkl
)
866 return USER_Driver
->pToUnicodeEx(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
, hkl
);
869 /****************************************************************************
872 INT WINAPI
ToAscii( UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
873 LPWORD lpChar
, UINT flags
)
875 return ToAsciiEx(virtKey
, scanCode
, lpKeyState
, lpChar
, flags
, GetKeyboardLayout(0));
878 /****************************************************************************
879 * ToAsciiEx (USER32.@)
881 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
882 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
887 ret
= ToUnicodeEx(virtKey
, scanCode
, lpKeyState
, uni_chars
, 2, flags
, dwhkl
);
888 if (ret
< 0) n_ret
= 1; /* FIXME: make ToUnicode return 2 for dead chars */
890 WideCharToMultiByte(CP_ACP
, 0, uni_chars
, n_ret
, (LPSTR
)lpChar
, 2, NULL
, NULL
);
894 /**********************************************************************
895 * ActivateKeyboardLayout (USER32.@)
897 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
899 TRACE_(keyboard
)("(%p, %d)\n", hLayout
, flags
);
901 return USER_Driver
->pActivateKeyboardLayout(hLayout
, flags
);
904 /**********************************************************************
905 * BlockInput (USER32.@)
907 BOOL WINAPI
BlockInput(BOOL fBlockIt
)
909 FIXME_(keyboard
)("(%d): stub\n", fBlockIt
);
910 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
915 /***********************************************************************
916 * GetKeyboardLayoutList (USER32.@)
918 * Return number of values available if either input parm is
919 * 0, per MS documentation.
921 UINT WINAPI
GetKeyboardLayoutList(INT nBuff
, HKL
*layouts
)
926 ULONG_PTR baselayout
;
928 static const WCHAR szKeyboardReg
[] = {'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\','C','o','n','t','r','o','l','\\','K','e','y','b','o','a','r','d',' ','L','a','y','o','u','t','s',0};
930 TRACE_(keyboard
)("(%d,%p)\n",nBuff
,layouts
);
932 baselayout
= GetUserDefaultLCID();
933 langid
= PRIMARYLANGID(LANGIDFROMLCID(baselayout
));
934 if (langid
== LANG_CHINESE
|| langid
== LANG_JAPANESE
|| langid
== LANG_KOREAN
)
935 baselayout
|= 0xe001 << 16; /* IME */
937 baselayout
|= baselayout
<< 16;
939 /* Enumerate the Registry */
940 rc
= RegOpenKeyW(HKEY_LOCAL_MACHINE
,szKeyboardReg
,&hKeyKeyboard
);
941 if (rc
== ERROR_SUCCESS
)
946 rc
= RegEnumKeyW(hKeyKeyboard
, count
, szKeyName
, 9);
947 if (rc
== ERROR_SUCCESS
)
949 layout
= (HKL
)(ULONG_PTR
)strtoulW(szKeyName
,NULL
,16);
950 if (baselayout
!= 0 && layout
== (HKL
)baselayout
)
951 baselayout
= 0; /* found in the registry do not add again */
952 if (nBuff
&& layouts
)
954 if (count
>= nBuff
) break;
955 layouts
[count
] = layout
;
959 } while (rc
== ERROR_SUCCESS
);
960 RegCloseKey(hKeyKeyboard
);
963 /* make sure our base layout is on the list */
966 if (nBuff
&& layouts
)
970 layouts
[count
] = (HKL
)baselayout
;
982 /***********************************************************************
983 * RegisterHotKey (USER32.@)
985 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
)
990 TRACE_(keyboard
)("(%p,%d,0x%08x,%X)\n",hwnd
,id
,modifiers
,vk
);
992 if ((hwnd
== NULL
|| WIN_IsCurrentThread(hwnd
)) &&
993 !USER_Driver
->pRegisterHotKey(hwnd
, modifiers
, vk
))
996 SERVER_START_REQ( register_hotkey
)
998 req
->window
= wine_server_user_handle( hwnd
);
1000 req
->flags
= modifiers
;
1002 if ((ret
= !wine_server_call_err( req
)))
1004 replaced
= reply
->replaced
;
1005 modifiers
= reply
->flags
;
1011 if (ret
&& replaced
)
1012 USER_Driver
->pUnregisterHotKey(hwnd
, modifiers
, vk
);
1017 /***********************************************************************
1018 * UnregisterHotKey (USER32.@)
1020 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
)
1025 TRACE_(keyboard
)("(%p,%d)\n",hwnd
,id
);
1027 SERVER_START_REQ( unregister_hotkey
)
1029 req
->window
= wine_server_user_handle( hwnd
);
1031 if ((ret
= !wine_server_call_err( req
)))
1033 modifiers
= reply
->flags
;
1040 USER_Driver
->pUnregisterHotKey(hwnd
, modifiers
, vk
);
1045 /***********************************************************************
1046 * LoadKeyboardLayoutW (USER32.@)
1048 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
1050 TRACE_(keyboard
)("(%s, %d)\n", debugstr_w(pwszKLID
), Flags
);
1052 return USER_Driver
->pLoadKeyboardLayout(pwszKLID
, Flags
);
1055 /***********************************************************************
1056 * LoadKeyboardLayoutA (USER32.@)
1058 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
1061 UNICODE_STRING pwszKLIDW
;
1063 if (pwszKLID
) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW
, pwszKLID
);
1064 else pwszKLIDW
.Buffer
= NULL
;
1066 ret
= LoadKeyboardLayoutW(pwszKLIDW
.Buffer
, Flags
);
1067 RtlFreeUnicodeString(&pwszKLIDW
);
1072 /***********************************************************************
1073 * UnloadKeyboardLayout (USER32.@)
1075 BOOL WINAPI
UnloadKeyboardLayout(HKL hkl
)
1077 TRACE_(keyboard
)("(%p)\n", hkl
);
1079 return USER_Driver
->pUnloadKeyboardLayout(hkl
);
1082 typedef struct __TRACKINGLIST
{
1083 TRACKMOUSEEVENT tme
;
1084 POINT pos
; /* center of hover rectangle */
1087 /* FIXME: move tracking stuff into a per thread data */
1088 static _TRACKINGLIST tracking_info
;
1089 static UINT_PTR timer
;
1091 static void check_mouse_leave(HWND hwnd
, int hittest
)
1093 if (tracking_info
.tme
.hwndTrack
!= hwnd
)
1095 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
1096 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
1098 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
1100 /* remove the TME_LEAVE flag */
1101 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
1105 if (hittest
== HTCLIENT
)
1107 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
1109 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
1110 /* remove the TME_LEAVE flag */
1111 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
1116 if (!(tracking_info
.tme
.dwFlags
& TME_NONCLIENT
))
1118 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
1119 /* remove the TME_LEAVE flag */
1120 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
1126 static void CALLBACK
TrackMouseEventProc(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
,
1130 INT hoverwidth
= 0, hoverheight
= 0, hittest
;
1132 TRACE("hwnd %p, msg %04x, id %04lx, time %u\n", hwnd
, uMsg
, idEvent
, dwTime
);
1135 hwnd
= WINPOS_WindowFromPoint(hwnd
, pos
, &hittest
);
1137 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos
), hwnd
, hittest
);
1139 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH
, 0, &hoverwidth
, 0);
1140 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT
, 0, &hoverheight
, 0);
1142 TRACE("tracked pos %s, current pos %s, hover width %d, hover height %d\n",
1143 wine_dbgstr_point(&tracking_info
.pos
), wine_dbgstr_point(&pos
),
1144 hoverwidth
, hoverheight
);
1146 /* see if this tracking event is looking for TME_LEAVE and that the */
1147 /* mouse has left the window */
1148 if (tracking_info
.tme
.dwFlags
& TME_LEAVE
)
1150 check_mouse_leave(hwnd
, hittest
);
1153 if (tracking_info
.tme
.hwndTrack
!= hwnd
)
1155 /* mouse is gone, stop tracking mouse hover */
1156 tracking_info
.tme
.dwFlags
&= ~TME_HOVER
;
1159 /* see if we are tracking hovering for this hwnd */
1160 if (tracking_info
.tme
.dwFlags
& TME_HOVER
)
1162 /* has the cursor moved outside the rectangle centered around pos? */
1163 if ((abs(pos
.x
- tracking_info
.pos
.x
) > (hoverwidth
/ 2)) ||
1164 (abs(pos
.y
- tracking_info
.pos
.y
) > (hoverheight
/ 2)))
1166 /* record this new position as the current position */
1167 tracking_info
.pos
= pos
;
1171 if (hittest
== HTCLIENT
)
1173 ScreenToClient(hwnd
, &pos
);
1174 TRACE("client cursor pos %s\n", wine_dbgstr_point(&pos
));
1176 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSEHOVER
,
1177 get_key_state(), MAKELPARAM( pos
.x
, pos
.y
));
1181 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
1182 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSEHOVER
,
1183 hittest
, MAKELPARAM( pos
.x
, pos
.y
));
1186 /* stop tracking mouse hover */
1187 tracking_info
.tme
.dwFlags
&= ~TME_HOVER
;
1191 /* stop the timer if the tracking list is empty */
1192 if (!(tracking_info
.tme
.dwFlags
& (TME_HOVER
| TME_LEAVE
)))
1194 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1196 tracking_info
.tme
.hwndTrack
= 0;
1197 tracking_info
.tme
.dwFlags
= 0;
1198 tracking_info
.tme
.dwHoverTime
= 0;
1203 /***********************************************************************
1204 * TrackMouseEvent [USER32]
1206 * Requests notification of mouse events
1208 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1209 * to the hwnd specified in the ptme structure. After the event message
1210 * is posted to the hwnd, the entry in the queue is removed.
1212 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1213 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1214 * immediately and the TME_LEAVE flag being ignored.
1217 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1226 TrackMouseEvent (TRACKMOUSEEVENT
*ptme
)
1233 TRACE("%x, %x, %p, %u\n", ptme
->cbSize
, ptme
->dwFlags
, ptme
->hwndTrack
, ptme
->dwHoverTime
);
1235 if (ptme
->cbSize
!= sizeof(TRACKMOUSEEVENT
)) {
1236 WARN("wrong TRACKMOUSEEVENT size from app\n");
1237 SetLastError(ERROR_INVALID_PARAMETER
);
1241 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1242 if (ptme
->dwFlags
& TME_QUERY
)
1244 *ptme
= tracking_info
.tme
;
1245 /* set cbSize in the case it's not initialized yet */
1246 ptme
->cbSize
= sizeof(TRACKMOUSEEVENT
);
1248 return TRUE
; /* return here, TME_QUERY is retrieving information */
1251 if (!IsWindow(ptme
->hwndTrack
))
1253 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1257 hover_time
= (ptme
->dwFlags
& TME_HOVER
) ? ptme
->dwHoverTime
: HOVER_DEFAULT
;
1259 /* if HOVER_DEFAULT was specified replace this with the system's current value.
1260 * TME_LEAVE doesn't need to specify hover time so use default */
1261 if (hover_time
== HOVER_DEFAULT
|| hover_time
== 0)
1262 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME
, 0, &hover_time
, 0);
1265 hwnd
= WINPOS_WindowFromPoint(ptme
->hwndTrack
, pos
, &hittest
);
1266 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos
), hwnd
, hittest
);
1268 if (ptme
->dwFlags
& ~(TME_CANCEL
| TME_HOVER
| TME_LEAVE
| TME_NONCLIENT
))
1269 FIXME("Unknown flag(s) %08x\n", ptme
->dwFlags
& ~(TME_CANCEL
| TME_HOVER
| TME_LEAVE
| TME_NONCLIENT
));
1271 if (ptme
->dwFlags
& TME_CANCEL
)
1273 if (tracking_info
.tme
.hwndTrack
== ptme
->hwndTrack
)
1275 tracking_info
.tme
.dwFlags
&= ~(ptme
->dwFlags
& ~TME_CANCEL
);
1277 /* if we aren't tracking on hover or leave remove this entry */
1278 if (!(tracking_info
.tme
.dwFlags
& (TME_HOVER
| TME_LEAVE
)))
1280 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1282 tracking_info
.tme
.hwndTrack
= 0;
1283 tracking_info
.tme
.dwFlags
= 0;
1284 tracking_info
.tme
.dwHoverTime
= 0;
1288 /* In our implementation it's possible that another window will receive a
1289 * WM_MOUSEMOVE and call TrackMouseEvent before TrackMouseEventProc is
1290 * called. In such a situation post the WM_MOUSELEAVE now */
1291 if (tracking_info
.tme
.dwFlags
& TME_LEAVE
&& tracking_info
.tme
.hwndTrack
!= NULL
)
1292 check_mouse_leave(hwnd
, hittest
);
1296 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1298 tracking_info
.tme
.hwndTrack
= 0;
1299 tracking_info
.tme
.dwFlags
= 0;
1300 tracking_info
.tme
.dwHoverTime
= 0;
1303 if (ptme
->hwndTrack
== hwnd
)
1305 /* Adding new mouse event to the tracking list */
1306 tracking_info
.tme
= *ptme
;
1307 tracking_info
.tme
.dwHoverTime
= hover_time
;
1309 /* Initialize HoverInfo variables even if not hover tracking */
1310 tracking_info
.pos
= pos
;
1312 timer
= SetSystemTimer(tracking_info
.tme
.hwndTrack
, (UINT_PTR
)&tracking_info
.tme
, hover_time
, TrackMouseEventProc
);
1319 /***********************************************************************
1320 * GetMouseMovePointsEx [USER32]
1323 * Success: count of point set in the buffer
1326 int WINAPI
GetMouseMovePointsEx(UINT size
, LPMOUSEMOVEPOINT ptin
, LPMOUSEMOVEPOINT ptout
, int count
, DWORD res
) {
1328 if((size
!= sizeof(MOUSEMOVEPOINT
)) || (count
< 0) || (count
> 64)) {
1329 SetLastError(ERROR_INVALID_PARAMETER
);
1333 if(!ptin
|| (!ptout
&& count
)) {
1334 SetLastError(ERROR_NOACCESS
);
1338 FIXME("(%d %p %p %d %d) stub\n", size
, ptin
, ptout
, count
, res
);
1340 SetLastError(ERROR_POINT_NOT_FOUND
);