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
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
);
55 INT global_key_state_counter
= 0;
57 /***********************************************************************
60 static WORD
get_key_state(void)
64 if (GetSystemMetrics( SM_SWAPBUTTON
))
66 if (GetAsyncKeyState(VK_RBUTTON
) & 0x80) ret
|= MK_LBUTTON
;
67 if (GetAsyncKeyState(VK_LBUTTON
) & 0x80) ret
|= MK_RBUTTON
;
71 if (GetAsyncKeyState(VK_LBUTTON
) & 0x80) ret
|= MK_LBUTTON
;
72 if (GetAsyncKeyState(VK_RBUTTON
) & 0x80) ret
|= MK_RBUTTON
;
74 if (GetAsyncKeyState(VK_MBUTTON
) & 0x80) ret
|= MK_MBUTTON
;
75 if (GetAsyncKeyState(VK_SHIFT
) & 0x80) ret
|= MK_SHIFT
;
76 if (GetAsyncKeyState(VK_CONTROL
) & 0x80) ret
|= MK_CONTROL
;
77 if (GetAsyncKeyState(VK_XBUTTON1
) & 0x80) ret
|= MK_XBUTTON1
;
78 if (GetAsyncKeyState(VK_XBUTTON2
) & 0x80) ret
|= MK_XBUTTON2
;
83 /**********************************************************************
86 BOOL
set_capture_window( HWND hwnd
, UINT gui_flags
, HWND
*prev_ret
)
92 if (gui_flags
& GUI_INMENUMODE
) flags
|= CAPTURE_MENU
;
93 if (gui_flags
& GUI_INMOVESIZE
) flags
|= CAPTURE_MOVESIZE
;
95 SERVER_START_REQ( set_capture_window
)
97 req
->handle
= wine_server_user_handle( hwnd
);
99 if ((ret
= !wine_server_call_err( req
)))
101 previous
= wine_server_ptr_handle( reply
->previous
);
102 hwnd
= wine_server_ptr_handle( reply
->full_handle
);
109 USER_Driver
->pSetCapture( hwnd
, gui_flags
);
111 if (previous
&& previous
!= hwnd
)
112 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
114 if (prev_ret
) *prev_ret
= previous
;
120 /***********************************************************************
121 * __wine_send_input (USER32.@)
123 * Internal SendInput function to allow the graphics driver to inject real events.
125 BOOL CDECL
__wine_send_input( HWND hwnd
, const INPUT
*input
)
127 NTSTATUS status
= send_hardware_message( hwnd
, input
, 0 );
128 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
133 /***********************************************************************
134 * update_mouse_coords
136 * Helper for SendInput.
138 static void update_mouse_coords( INPUT
*input
)
140 if (!(input
->u
.mi
.dwFlags
& MOUSEEVENTF_MOVE
)) return;
142 if (input
->u
.mi
.dwFlags
& MOUSEEVENTF_ABSOLUTE
)
144 input
->u
.mi
.dx
= (input
->u
.mi
.dx
* GetSystemMetrics( SM_CXSCREEN
)) >> 16;
145 input
->u
.mi
.dy
= (input
->u
.mi
.dy
* GetSystemMetrics( SM_CYSCREEN
)) >> 16;
151 /* dx and dy can be negative numbers for relative movements */
152 SystemParametersInfoW(SPI_GETMOUSE
, 0, accel
, 0);
154 if (!accel
[2]) return;
156 if (abs(input
->u
.mi
.dx
) > accel
[0])
159 if ((abs(input
->u
.mi
.dx
) > accel
[1]) && (accel
[2] == 2)) input
->u
.mi
.dx
*= 2;
161 if (abs(input
->u
.mi
.dy
) > accel
[0])
164 if ((abs(input
->u
.mi
.dy
) > accel
[1]) && (accel
[2] == 2)) input
->u
.mi
.dy
*= 2;
169 /***********************************************************************
170 * SendInput (USER32.@)
172 UINT WINAPI
SendInput( UINT count
, LPINPUT inputs
, int size
)
177 for (i
= 0; i
< count
; i
++)
179 if (inputs
[i
].type
== INPUT_MOUSE
)
181 /* we need to update the coordinates to what the server expects */
182 INPUT input
= inputs
[i
];
183 update_mouse_coords( &input
);
184 status
= send_hardware_message( 0, &input
, SEND_HWMSG_INJECTED
);
186 else status
= send_hardware_message( 0, &inputs
[i
], SEND_HWMSG_INJECTED
);
190 SetLastError( RtlNtStatusToDosError(status
) );
199 /***********************************************************************
200 * keybd_event (USER32.@)
202 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
203 DWORD dwFlags
, ULONG_PTR dwExtraInfo
)
207 input
.type
= INPUT_KEYBOARD
;
208 input
.u
.ki
.wVk
= bVk
;
209 input
.u
.ki
.wScan
= bScan
;
210 input
.u
.ki
.dwFlags
= dwFlags
;
212 input
.u
.ki
.dwExtraInfo
= dwExtraInfo
;
213 SendInput( 1, &input
, sizeof(input
) );
217 /***********************************************************************
218 * mouse_event (USER32.@)
220 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
221 DWORD dwData
, ULONG_PTR dwExtraInfo
)
225 input
.type
= INPUT_MOUSE
;
228 input
.u
.mi
.mouseData
= dwData
;
229 input
.u
.mi
.dwFlags
= dwFlags
;
231 input
.u
.mi
.dwExtraInfo
= dwExtraInfo
;
232 SendInput( 1, &input
, sizeof(input
) );
236 /***********************************************************************
237 * GetCursorPos (USER32.@)
239 BOOL WINAPI DECLSPEC_HOTPATCH
GetCursorPos( POINT
*pt
)
244 if (!pt
) return FALSE
;
246 SERVER_START_REQ( set_cursor
)
248 if ((ret
= !wine_server_call( req
)))
250 pt
->x
= reply
->new_x
;
251 pt
->y
= reply
->new_y
;
252 last_change
= reply
->last_change
;
257 /* query new position from graphics driver if we haven't updated recently */
258 if (ret
&& GetTickCount() - last_change
> 100) ret
= USER_Driver
->pGetCursorPos( pt
);
263 /***********************************************************************
264 * GetCursorInfo (USER32.@)
266 BOOL WINAPI
GetCursorInfo( PCURSORINFO pci
)
270 if (!pci
) return FALSE
;
272 SERVER_START_REQ( get_thread_input
)
275 if ((ret
= !wine_server_call( req
)))
277 pci
->hCursor
= wine_server_ptr_handle( reply
->cursor
);
278 pci
->flags
= (reply
->show_count
>= 0) ? CURSOR_SHOWING
: 0;
282 GetCursorPos(&pci
->ptScreenPos
);
287 /***********************************************************************
288 * SetCursorPos (USER32.@)
290 BOOL WINAPI DECLSPEC_HOTPATCH
SetCursorPos( INT x
, INT y
)
293 INT prev_x
, prev_y
, new_x
, new_y
;
295 SERVER_START_REQ( set_cursor
)
297 req
->flags
= SET_CURSOR_POS
;
300 if ((ret
= !wine_server_call( req
)))
302 prev_x
= reply
->prev_x
;
303 prev_y
= reply
->prev_y
;
304 new_x
= reply
->new_x
;
305 new_y
= reply
->new_y
;
309 if (ret
&& (prev_x
!= new_x
|| prev_y
!= new_y
)) USER_Driver
->pSetCursorPos( new_x
, new_y
);
314 /**********************************************************************
315 * SetCapture (USER32.@)
317 HWND WINAPI DECLSPEC_HOTPATCH
SetCapture( HWND hwnd
)
321 set_capture_window( hwnd
, 0, &previous
);
326 /**********************************************************************
327 * ReleaseCapture (USER32.@)
329 BOOL WINAPI DECLSPEC_HOTPATCH
ReleaseCapture(void)
331 BOOL ret
= set_capture_window( 0, 0, NULL
);
333 /* Somebody may have missed some mouse movements */
334 if (ret
) mouse_event( MOUSEEVENTF_MOVE
, 0, 0, 0, 0 );
340 /**********************************************************************
341 * GetCapture (USER32.@)
343 HWND WINAPI
GetCapture(void)
347 SERVER_START_REQ( get_thread_input
)
349 req
->tid
= GetCurrentThreadId();
350 if (!wine_server_call_err( req
)) ret
= wine_server_ptr_handle( reply
->capture
);
357 static void check_for_events( UINT flags
)
359 if (USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, flags
, 0 ) == WAIT_TIMEOUT
)
360 flush_window_surfaces( TRUE
);
363 /**********************************************************************
364 * GetAsyncKeyState (USER32.@)
366 * Determine if a key is or was pressed. retval has high-order
367 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
370 SHORT WINAPI DECLSPEC_HOTPATCH
GetAsyncKeyState( INT key
)
372 struct user_key_state_info
*key_state_info
= get_user_thread_info()->key_state
;
373 INT counter
= global_key_state_counter
;
376 if (key
< 0 || key
>= 256) return 0;
378 check_for_events( QS_INPUT
);
380 if ((ret
= USER_Driver
->pGetAsyncKeyState( key
)) == -1)
382 if (key_state_info
&&
383 !(key_state_info
->state
[key
] & 0xc0) &&
384 key_state_info
->counter
== counter
&&
385 GetTickCount() - key_state_info
->time
< 50)
387 /* use cached value */
390 else if (!key_state_info
)
392 key_state_info
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*key_state_info
) );
393 get_user_thread_info()->key_state
= key_state_info
;
397 SERVER_START_REQ( get_key_state
)
401 if (key_state_info
) wine_server_set_reply( req
, key_state_info
->state
,
402 sizeof(key_state_info
->state
) );
403 if (!wine_server_call( req
))
405 if (reply
->state
& 0x40) ret
|= 0x0001;
406 if (reply
->state
& 0x80) ret
|= 0x8000;
409 key_state_info
->time
= GetTickCount();
410 key_state_info
->counter
= counter
;
420 /***********************************************************************
421 * GetQueueStatus (USER32.@)
423 DWORD WINAPI
GetQueueStatus( UINT flags
)
427 if (flags
& ~(QS_ALLINPUT
| QS_ALLPOSTMESSAGE
| QS_SMRESULT
))
429 SetLastError( ERROR_INVALID_FLAGS
);
433 check_for_events( flags
);
435 SERVER_START_REQ( get_queue_status
)
437 req
->clear_bits
= flags
;
438 wine_server_call( req
);
439 ret
= MAKELONG( reply
->changed_bits
& flags
, reply
->wake_bits
& flags
);
446 /***********************************************************************
447 * GetInputState (USER32.@)
449 BOOL WINAPI
GetInputState(void)
453 check_for_events( QS_INPUT
);
455 SERVER_START_REQ( get_queue_status
)
458 wine_server_call( req
);
459 ret
= reply
->wake_bits
& (QS_KEY
| QS_MOUSEBUTTON
);
466 /******************************************************************
467 * GetLastInputInfo (USER32.@)
469 BOOL WINAPI
GetLastInputInfo(PLASTINPUTINFO plii
)
475 if (plii
->cbSize
!= sizeof (*plii
) )
477 SetLastError(ERROR_INVALID_PARAMETER
);
481 SERVER_START_REQ( get_last_input_time
)
483 ret
= !wine_server_call_err( req
);
485 plii
->dwTime
= reply
->time
;
492 /******************************************************************
493 * GetRawInputDeviceList (USER32.@)
495 UINT WINAPI
GetRawInputDeviceList(RAWINPUTDEVICELIST
*devices
, UINT
*device_count
, UINT size
)
497 TRACE("devices %p, device_count %p, size %u.\n", devices
, device_count
, size
);
499 if (size
!= sizeof(*devices
) || !device_count
) return ~0U;
507 if (*device_count
< 2)
513 devices
[0].hDevice
= WINE_MOUSE_HANDLE
;
514 devices
[0].dwType
= RIM_TYPEMOUSE
;
515 devices
[1].hDevice
= WINE_KEYBOARD_HANDLE
;
516 devices
[1].dwType
= RIM_TYPEKEYBOARD
;
522 /******************************************************************
523 * RegisterRawInputDevices (USER32.@)
525 BOOL WINAPI DECLSPEC_HOTPATCH
RegisterRawInputDevices(RAWINPUTDEVICE
*devices
, UINT device_count
, UINT size
)
527 struct rawinput_device
*d
;
531 TRACE("devices %p, device_count %u, size %u.\n", devices
, device_count
, size
);
533 if (size
!= sizeof(*devices
))
535 WARN("Invalid structure size %u.\n", size
);
539 if (!(d
= HeapAlloc( GetProcessHeap(), 0, device_count
* sizeof(*d
) ))) return FALSE
;
541 for (i
= 0; i
< device_count
; ++i
)
543 TRACE("device %u: page %#x, usage %#x, flags %#x, target %p.\n",
544 i
, devices
[i
].usUsagePage
, devices
[i
].usUsage
,
545 devices
[i
].dwFlags
, devices
[i
].hwndTarget
);
546 if (devices
[i
].dwFlags
& ~RIDEV_REMOVE
)
547 FIXME("Unhandled flags %#x for device %u.\n", devices
[i
].dwFlags
, i
);
549 d
[i
].usage_page
= devices
[i
].usUsagePage
;
550 d
[i
].usage
= devices
[i
].usUsage
;
551 d
[i
].flags
= devices
[i
].dwFlags
;
552 d
[i
].target
= wine_server_user_handle( devices
[i
].hwndTarget
);
555 SERVER_START_REQ( update_rawinput_devices
)
557 wine_server_add_data( req
, d
, device_count
* sizeof(*d
) );
558 ret
= !wine_server_call( req
);
562 HeapFree( GetProcessHeap(), 0, d
);
568 /******************************************************************
569 * GetRawInputData (USER32.@)
571 UINT WINAPI
GetRawInputData(HRAWINPUT rawinput
, UINT command
, void *data
, UINT
*data_size
, UINT header_size
)
573 RAWINPUT
*ri
= (RAWINPUT
*)rawinput
;
576 TRACE("rawinput %p, command %#x, data %p, data_size %p, header_size %u.\n",
577 rawinput
, command
, data
, data_size
, header_size
);
579 if (header_size
!= sizeof(RAWINPUTHEADER
))
581 WARN("Invalid structure size %u.\n", header_size
);
588 s
= ri
->header
.dwSize
;
591 s
= sizeof(RAWINPUTHEADER
);
603 if (*data_size
< s
) return ~0U;
609 /******************************************************************
610 * GetRawInputBuffer (USER32.@)
612 UINT WINAPI DECLSPEC_HOTPATCH
GetRawInputBuffer(PRAWINPUT pData
, PUINT pcbSize
, UINT cbSizeHeader
)
614 FIXME("(pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n", pData
, pcbSize
, cbSizeHeader
);
620 /******************************************************************
621 * GetRawInputDeviceInfoA (USER32.@)
623 UINT WINAPI
GetRawInputDeviceInfoA(HANDLE device
, UINT command
, void *data
, UINT
*data_size
)
627 TRACE("device %p, command %u, data %p, data_size %p.\n", device
, command
, data
, data_size
);
629 ret
= GetRawInputDeviceInfoW(device
, command
, data
, data_size
);
630 if (command
== RIDI_DEVICENAME
&& ret
&& ret
!= ~0U)
631 ret
= WideCharToMultiByte(CP_ACP
, 0, data
, -1, data
, *data_size
, NULL
, NULL
);
637 /******************************************************************
638 * GetRawInputDeviceInfoW (USER32.@)
640 UINT WINAPI
GetRawInputDeviceInfoW(HANDLE device
, UINT command
, void *data
, UINT
*data_size
)
642 /* FIXME: Most of this is made up. */
643 static const WCHAR keyboard_name
[] = {'\\','\\','?','\\','W','I','N','E','_','K','E','Y','B','O','A','R','D',0};
644 static const WCHAR mouse_name
[] = {'\\','\\','?','\\','W','I','N','E','_','M','O','U','S','E',0};
645 static const RID_DEVICE_INFO_KEYBOARD keyboard_info
= {0, 0, 1, 12, 3, 101};
646 static const RID_DEVICE_INFO_MOUSE mouse_info
= {1, 5, 0, FALSE
};
647 const WCHAR
*name
= NULL
;
648 RID_DEVICE_INFO
*info
;
651 TRACE("device %p, command %u, data %p, data_size %p.\n", device
, command
, data
, data_size
);
653 if (!data_size
|| (device
!= WINE_MOUSE_HANDLE
&& device
!= WINE_KEYBOARD_HANDLE
)) return ~0U;
657 case RIDI_DEVICENAME
:
658 if (device
== WINE_MOUSE_HANDLE
)
660 s
= sizeof(mouse_name
);
665 s
= sizeof(keyboard_name
);
666 name
= keyboard_name
;
669 case RIDI_DEVICEINFO
:
688 if (command
== RIDI_DEVICENAME
)
690 memcpy(data
, name
, s
);
695 info
->cbSize
= sizeof(*info
);
696 if (device
== WINE_MOUSE_HANDLE
)
698 info
->dwType
= RIM_TYPEMOUSE
;
699 info
->u
.mouse
= mouse_info
;
703 info
->dwType
= RIM_TYPEKEYBOARD
;
704 info
->u
.keyboard
= keyboard_info
;
710 /******************************************************************
711 * GetRegisteredRawInputDevices (USER32.@)
713 UINT WINAPI DECLSPEC_HOTPATCH
GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices
, PUINT puiNumDevices
, UINT cbSize
)
715 FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices
, puiNumDevices
, cbSize
);
721 /******************************************************************
722 * DefRawInputProc (USER32.@)
724 LRESULT WINAPI
DefRawInputProc(PRAWINPUT
*paRawInput
, INT nInput
, UINT cbSizeHeader
)
726 FIXME("(paRawInput=%p, nInput=%d, cbSizeHeader=%d) stub!\n", *paRawInput
, nInput
, cbSizeHeader
);
732 /**********************************************************************
733 * AttachThreadInput (USER32.@)
735 * Attaches the input processing mechanism of one thread to that of
738 BOOL WINAPI
AttachThreadInput( DWORD from
, DWORD to
, BOOL attach
)
742 SERVER_START_REQ( attach_thread_input
)
744 req
->tid_from
= from
;
746 req
->attach
= attach
;
747 ret
= !wine_server_call_err( req
);
754 /**********************************************************************
755 * GetKeyState (USER32.@)
757 * An application calls the GetKeyState function in response to a
758 * keyboard-input message. This function retrieves the state of the key
759 * at the time the input message was generated.
761 SHORT WINAPI DECLSPEC_HOTPATCH
GetKeyState(INT vkey
)
765 SERVER_START_REQ( get_key_state
)
767 req
->tid
= GetCurrentThreadId();
769 if (!wine_server_call( req
)) retval
= (signed char)reply
->state
;
772 TRACE("key (0x%x) -> %x\n", vkey
, retval
);
777 /**********************************************************************
778 * GetKeyboardState (USER32.@)
780 BOOL WINAPI DECLSPEC_HOTPATCH
GetKeyboardState( LPBYTE state
)
784 TRACE("(%p)\n", state
);
786 memset( state
, 0, 256 );
787 SERVER_START_REQ( get_key_state
)
789 req
->tid
= GetCurrentThreadId();
791 wine_server_set_reply( req
, state
, 256 );
792 ret
= !wine_server_call_err( req
);
799 /**********************************************************************
800 * SetKeyboardState (USER32.@)
802 BOOL WINAPI
SetKeyboardState( LPBYTE state
)
806 SERVER_START_REQ( set_key_state
)
808 req
->tid
= GetCurrentThreadId();
809 wine_server_add_data( req
, state
, 256 );
810 ret
= !wine_server_call_err( req
);
817 /**********************************************************************
818 * VkKeyScanA (USER32.@)
820 * VkKeyScan translates an ANSI character to a virtual-key and shift code
821 * for the current keyboard.
822 * high-order byte yields :
826 * 3-5 Shift-key combinations that are not used for characters
829 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
830 * FIXME : works ok except for dead chars :
831 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
832 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
834 SHORT WINAPI
VkKeyScanA(CHAR cChar
)
838 if (IsDBCSLeadByte(cChar
)) return -1;
840 MultiByteToWideChar(CP_ACP
, 0, &cChar
, 1, &wChar
, 1);
841 return VkKeyScanW(wChar
);
844 /******************************************************************************
845 * VkKeyScanW (USER32.@)
847 SHORT WINAPI
VkKeyScanW(WCHAR cChar
)
849 return VkKeyScanExW(cChar
, GetKeyboardLayout(0));
852 /**********************************************************************
853 * VkKeyScanExA (USER32.@)
855 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
859 if (IsDBCSLeadByte(cChar
)) return -1;
861 MultiByteToWideChar(CP_ACP
, 0, &cChar
, 1, &wChar
, 1);
862 return VkKeyScanExW(wChar
, dwhkl
);
865 /******************************************************************************
866 * VkKeyScanExW (USER32.@)
868 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
870 return USER_Driver
->pVkKeyScanEx(cChar
, dwhkl
);
873 /**********************************************************************
874 * OemKeyScan (USER32.@)
876 DWORD WINAPI
OemKeyScan(WORD wOemChar
)
881 /******************************************************************************
882 * GetKeyboardType (USER32.@)
884 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
886 TRACE_(keyboard
)("(%d)\n", nTypeFlag
);
889 case 0: /* Keyboard type */
890 return 4; /* AT-101 */
891 case 1: /* Keyboard Subtype */
892 return 0; /* There are no defined subtypes */
893 case 2: /* Number of F-keys */
894 return 12; /* We're doing an 101 for now, so return 12 F-keys */
896 WARN_(keyboard
)("Unknown type\n");
897 return 0; /* The book says 0 here, so 0 */
901 /******************************************************************************
902 * MapVirtualKeyA (USER32.@)
904 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
906 return MapVirtualKeyExA( code
, maptype
, GetKeyboardLayout(0) );
909 /******************************************************************************
910 * MapVirtualKeyW (USER32.@)
912 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
914 return MapVirtualKeyExW(code
, maptype
, GetKeyboardLayout(0));
917 /******************************************************************************
918 * MapVirtualKeyExA (USER32.@)
920 UINT WINAPI
MapVirtualKeyExA(UINT code
, UINT maptype
, HKL hkl
)
924 ret
= MapVirtualKeyExW( code
, maptype
, hkl
);
925 if (maptype
== MAPVK_VK_TO_CHAR
)
930 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, (LPSTR
)&ch
, 1, NULL
, NULL
);
936 /******************************************************************************
937 * MapVirtualKeyExW (USER32.@)
939 UINT WINAPI
MapVirtualKeyExW(UINT code
, UINT maptype
, HKL hkl
)
941 TRACE_(keyboard
)("(%X, %d, %p)\n", code
, maptype
, hkl
);
943 return USER_Driver
->pMapVirtualKeyEx(code
, maptype
, hkl
);
946 /****************************************************************************
947 * GetKBCodePage (USER32.@)
949 UINT WINAPI
GetKBCodePage(void)
954 /***********************************************************************
955 * GetKeyboardLayout (USER32.@)
957 * - device handle for keyboard layout defaulted to
958 * the language id. This is the way Windows default works.
959 * - the thread identifier is also ignored.
961 HKL WINAPI
GetKeyboardLayout(DWORD thread_id
)
963 return USER_Driver
->pGetKeyboardLayout(thread_id
);
966 /****************************************************************************
967 * GetKeyboardLayoutNameA (USER32.@)
969 BOOL WINAPI
GetKeyboardLayoutNameA(LPSTR pszKLID
)
971 WCHAR buf
[KL_NAMELENGTH
];
973 if (GetKeyboardLayoutNameW(buf
))
974 return WideCharToMultiByte( CP_ACP
, 0, buf
, -1, pszKLID
, KL_NAMELENGTH
, NULL
, NULL
) != 0;
978 /****************************************************************************
979 * GetKeyboardLayoutNameW (USER32.@)
981 BOOL WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
985 SetLastError(ERROR_NOACCESS
);
988 return USER_Driver
->pGetKeyboardLayoutName(pwszKLID
);
991 /****************************************************************************
992 * GetKeyNameTextA (USER32.@)
994 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
999 if (!nSize
|| !GetKeyNameTextW(lParam
, buf
, 256))
1004 ret
= WideCharToMultiByte(CP_ACP
, 0, buf
, -1, lpBuffer
, nSize
, NULL
, NULL
);
1015 /****************************************************************************
1016 * GetKeyNameTextW (USER32.@)
1018 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
1020 if (!lpBuffer
|| !nSize
) return 0;
1021 return USER_Driver
->pGetKeyNameText( lParam
, lpBuffer
, nSize
);
1024 /****************************************************************************
1025 * ToUnicode (USER32.@)
1027 INT WINAPI
ToUnicode(UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
1028 LPWSTR lpwStr
, int size
, UINT flags
)
1030 return ToUnicodeEx(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
, GetKeyboardLayout(0));
1033 /****************************************************************************
1034 * ToUnicodeEx (USER32.@)
1036 INT WINAPI
ToUnicodeEx(UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
1037 LPWSTR lpwStr
, int size
, UINT flags
, HKL hkl
)
1039 if (!lpKeyState
) return 0;
1040 return USER_Driver
->pToUnicodeEx(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
, hkl
);
1043 /****************************************************************************
1044 * ToAscii (USER32.@)
1046 INT WINAPI
ToAscii( UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
1047 LPWORD lpChar
, UINT flags
)
1049 return ToAsciiEx(virtKey
, scanCode
, lpKeyState
, lpChar
, flags
, GetKeyboardLayout(0));
1052 /****************************************************************************
1053 * ToAsciiEx (USER32.@)
1055 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
1056 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
1061 ret
= ToUnicodeEx(virtKey
, scanCode
, lpKeyState
, uni_chars
, 2, flags
, dwhkl
);
1062 if (ret
< 0) n_ret
= 1; /* FIXME: make ToUnicode return 2 for dead chars */
1064 WideCharToMultiByte(CP_ACP
, 0, uni_chars
, n_ret
, (LPSTR
)lpChar
, 2, NULL
, NULL
);
1068 /**********************************************************************
1069 * ActivateKeyboardLayout (USER32.@)
1071 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
1073 TRACE_(keyboard
)("(%p, %d)\n", hLayout
, flags
);
1075 return USER_Driver
->pActivateKeyboardLayout(hLayout
, flags
);
1078 /**********************************************************************
1079 * BlockInput (USER32.@)
1081 BOOL WINAPI
BlockInput(BOOL fBlockIt
)
1083 FIXME_(keyboard
)("(%d): stub\n", fBlockIt
);
1084 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1089 /***********************************************************************
1090 * GetKeyboardLayoutList (USER32.@)
1092 * Return number of values available if either input parm is
1093 * 0, per MS documentation.
1095 UINT WINAPI
GetKeyboardLayoutList(INT nBuff
, HKL
*layouts
)
1097 TRACE_(keyboard
)( "(%d, %p)\n", nBuff
, layouts
);
1099 return USER_Driver
->pGetKeyboardLayoutList( nBuff
, layouts
);
1103 /***********************************************************************
1104 * RegisterHotKey (USER32.@)
1106 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
)
1111 TRACE_(keyboard
)("(%p,%d,0x%08x,%X)\n",hwnd
,id
,modifiers
,vk
);
1113 if ((hwnd
== NULL
|| WIN_IsCurrentThread(hwnd
)) &&
1114 !USER_Driver
->pRegisterHotKey(hwnd
, modifiers
, vk
))
1117 SERVER_START_REQ( register_hotkey
)
1119 req
->window
= wine_server_user_handle( hwnd
);
1121 req
->flags
= modifiers
;
1123 if ((ret
= !wine_server_call_err( req
)))
1125 replaced
= reply
->replaced
;
1126 modifiers
= reply
->flags
;
1132 if (ret
&& replaced
)
1133 USER_Driver
->pUnregisterHotKey(hwnd
, modifiers
, vk
);
1138 /***********************************************************************
1139 * UnregisterHotKey (USER32.@)
1141 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
)
1146 TRACE_(keyboard
)("(%p,%d)\n",hwnd
,id
);
1148 SERVER_START_REQ( unregister_hotkey
)
1150 req
->window
= wine_server_user_handle( hwnd
);
1152 if ((ret
= !wine_server_call_err( req
)))
1154 modifiers
= reply
->flags
;
1161 USER_Driver
->pUnregisterHotKey(hwnd
, modifiers
, vk
);
1166 /***********************************************************************
1167 * LoadKeyboardLayoutW (USER32.@)
1169 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
1171 TRACE_(keyboard
)("(%s, %d)\n", debugstr_w(pwszKLID
), Flags
);
1173 return USER_Driver
->pLoadKeyboardLayout(pwszKLID
, Flags
);
1176 /***********************************************************************
1177 * LoadKeyboardLayoutA (USER32.@)
1179 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
1182 UNICODE_STRING pwszKLIDW
;
1184 if (pwszKLID
) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW
, pwszKLID
);
1185 else pwszKLIDW
.Buffer
= NULL
;
1187 ret
= LoadKeyboardLayoutW(pwszKLIDW
.Buffer
, Flags
);
1188 RtlFreeUnicodeString(&pwszKLIDW
);
1193 /***********************************************************************
1194 * UnloadKeyboardLayout (USER32.@)
1196 BOOL WINAPI
UnloadKeyboardLayout(HKL hkl
)
1198 TRACE_(keyboard
)("(%p)\n", hkl
);
1200 return USER_Driver
->pUnloadKeyboardLayout(hkl
);
1203 typedef struct __TRACKINGLIST
{
1204 TRACKMOUSEEVENT tme
;
1205 POINT pos
; /* center of hover rectangle */
1208 /* FIXME: move tracking stuff into a per thread data */
1209 static _TRACKINGLIST tracking_info
;
1210 static UINT_PTR timer
;
1212 static void check_mouse_leave(HWND hwnd
, int hittest
)
1214 if (tracking_info
.tme
.hwndTrack
!= hwnd
)
1216 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
1217 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
1219 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
1221 /* remove the TME_LEAVE flag */
1222 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
1226 if (hittest
== HTCLIENT
)
1228 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
1230 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
1231 /* remove the TME_LEAVE flag */
1232 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
1237 if (!(tracking_info
.tme
.dwFlags
& TME_NONCLIENT
))
1239 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
1240 /* remove the TME_LEAVE flag */
1241 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
1247 static void CALLBACK
TrackMouseEventProc(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
,
1251 INT hoverwidth
= 0, hoverheight
= 0, hittest
;
1253 TRACE("hwnd %p, msg %04x, id %04lx, time %u\n", hwnd
, uMsg
, idEvent
, dwTime
);
1256 hwnd
= WINPOS_WindowFromPoint(hwnd
, pos
, &hittest
);
1258 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos
), hwnd
, hittest
);
1260 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH
, 0, &hoverwidth
, 0);
1261 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT
, 0, &hoverheight
, 0);
1263 TRACE("tracked pos %s, current pos %s, hover width %d, hover height %d\n",
1264 wine_dbgstr_point(&tracking_info
.pos
), wine_dbgstr_point(&pos
),
1265 hoverwidth
, hoverheight
);
1267 /* see if this tracking event is looking for TME_LEAVE and that the */
1268 /* mouse has left the window */
1269 if (tracking_info
.tme
.dwFlags
& TME_LEAVE
)
1271 check_mouse_leave(hwnd
, hittest
);
1274 if (tracking_info
.tme
.hwndTrack
!= hwnd
)
1276 /* mouse is gone, stop tracking mouse hover */
1277 tracking_info
.tme
.dwFlags
&= ~TME_HOVER
;
1280 /* see if we are tracking hovering for this hwnd */
1281 if (tracking_info
.tme
.dwFlags
& TME_HOVER
)
1283 /* has the cursor moved outside the rectangle centered around pos? */
1284 if ((abs(pos
.x
- tracking_info
.pos
.x
) > (hoverwidth
/ 2)) ||
1285 (abs(pos
.y
- tracking_info
.pos
.y
) > (hoverheight
/ 2)))
1287 /* record this new position as the current position */
1288 tracking_info
.pos
= pos
;
1292 if (hittest
== HTCLIENT
)
1294 ScreenToClient(hwnd
, &pos
);
1295 TRACE("client cursor pos %s\n", wine_dbgstr_point(&pos
));
1297 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSEHOVER
,
1298 get_key_state(), MAKELPARAM( pos
.x
, pos
.y
));
1302 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
1303 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSEHOVER
,
1304 hittest
, MAKELPARAM( pos
.x
, pos
.y
));
1307 /* stop tracking mouse hover */
1308 tracking_info
.tme
.dwFlags
&= ~TME_HOVER
;
1312 /* stop the timer if the tracking list is empty */
1313 if (!(tracking_info
.tme
.dwFlags
& (TME_HOVER
| TME_LEAVE
)))
1315 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1317 tracking_info
.tme
.hwndTrack
= 0;
1318 tracking_info
.tme
.dwFlags
= 0;
1319 tracking_info
.tme
.dwHoverTime
= 0;
1324 /***********************************************************************
1325 * TrackMouseEvent [USER32]
1327 * Requests notification of mouse events
1329 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1330 * to the hwnd specified in the ptme structure. After the event message
1331 * is posted to the hwnd, the entry in the queue is removed.
1333 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1334 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1335 * immediately and the TME_LEAVE flag being ignored.
1338 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1347 TrackMouseEvent (TRACKMOUSEEVENT
*ptme
)
1354 TRACE("%x, %x, %p, %u\n", ptme
->cbSize
, ptme
->dwFlags
, ptme
->hwndTrack
, ptme
->dwHoverTime
);
1356 if (ptme
->cbSize
!= sizeof(TRACKMOUSEEVENT
)) {
1357 WARN("wrong TRACKMOUSEEVENT size from app\n");
1358 SetLastError(ERROR_INVALID_PARAMETER
);
1362 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1363 if (ptme
->dwFlags
& TME_QUERY
)
1365 *ptme
= tracking_info
.tme
;
1366 /* set cbSize in the case it's not initialized yet */
1367 ptme
->cbSize
= sizeof(TRACKMOUSEEVENT
);
1369 return TRUE
; /* return here, TME_QUERY is retrieving information */
1372 if (!IsWindow(ptme
->hwndTrack
))
1374 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1378 hover_time
= (ptme
->dwFlags
& TME_HOVER
) ? ptme
->dwHoverTime
: HOVER_DEFAULT
;
1380 /* if HOVER_DEFAULT was specified replace this with the system's current value.
1381 * TME_LEAVE doesn't need to specify hover time so use default */
1382 if (hover_time
== HOVER_DEFAULT
|| hover_time
== 0)
1383 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME
, 0, &hover_time
, 0);
1386 hwnd
= WINPOS_WindowFromPoint(ptme
->hwndTrack
, pos
, &hittest
);
1387 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos
), hwnd
, hittest
);
1389 if (ptme
->dwFlags
& ~(TME_CANCEL
| TME_HOVER
| TME_LEAVE
| TME_NONCLIENT
))
1390 FIXME("Unknown flag(s) %08x\n", ptme
->dwFlags
& ~(TME_CANCEL
| TME_HOVER
| TME_LEAVE
| TME_NONCLIENT
));
1392 if (ptme
->dwFlags
& TME_CANCEL
)
1394 if (tracking_info
.tme
.hwndTrack
== ptme
->hwndTrack
)
1396 tracking_info
.tme
.dwFlags
&= ~(ptme
->dwFlags
& ~TME_CANCEL
);
1398 /* if we aren't tracking on hover or leave remove this entry */
1399 if (!(tracking_info
.tme
.dwFlags
& (TME_HOVER
| TME_LEAVE
)))
1401 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1403 tracking_info
.tme
.hwndTrack
= 0;
1404 tracking_info
.tme
.dwFlags
= 0;
1405 tracking_info
.tme
.dwHoverTime
= 0;
1409 /* In our implementation it's possible that another window will receive a
1410 * WM_MOUSEMOVE and call TrackMouseEvent before TrackMouseEventProc is
1411 * called. In such a situation post the WM_MOUSELEAVE now */
1412 if (tracking_info
.tme
.dwFlags
& TME_LEAVE
&& tracking_info
.tme
.hwndTrack
!= NULL
)
1413 check_mouse_leave(hwnd
, hittest
);
1417 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1419 tracking_info
.tme
.hwndTrack
= 0;
1420 tracking_info
.tme
.dwFlags
= 0;
1421 tracking_info
.tme
.dwHoverTime
= 0;
1424 if (ptme
->hwndTrack
== hwnd
)
1426 /* Adding new mouse event to the tracking list */
1427 tracking_info
.tme
= *ptme
;
1428 tracking_info
.tme
.dwHoverTime
= hover_time
;
1430 /* Initialize HoverInfo variables even if not hover tracking */
1431 tracking_info
.pos
= pos
;
1433 timer
= SetSystemTimer(tracking_info
.tme
.hwndTrack
, (UINT_PTR
)&tracking_info
.tme
, hover_time
, TrackMouseEventProc
);
1440 /***********************************************************************
1441 * GetMouseMovePointsEx [USER32]
1444 * Success: count of point set in the buffer
1447 int WINAPI
GetMouseMovePointsEx(UINT size
, LPMOUSEMOVEPOINT ptin
, LPMOUSEMOVEPOINT ptout
, int count
, DWORD res
) {
1449 if((size
!= sizeof(MOUSEMOVEPOINT
)) || (count
< 0) || (count
> 64)) {
1450 SetLastError(ERROR_INVALID_PARAMETER
);
1454 if(!ptin
|| (!ptout
&& count
)) {
1455 SetLastError(ERROR_NOACCESS
);
1459 FIXME("(%d %p %p %d %d) stub\n", size
, ptin
, ptout
, count
, res
);
1461 SetLastError(ERROR_POINT_NOT_FOUND
);