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
);
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 DPI_AWARENESS_CONTEXT context
= SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
145 if (input
->u
.mi
.dwFlags
& MOUSEEVENTF_VIRTUALDESK
)
147 RECT rc
= get_virtual_screen_rect();
148 input
->u
.mi
.dx
= rc
.left
+ ((input
->u
.mi
.dx
* (rc
.right
- rc
.left
)) >> 16);
149 input
->u
.mi
.dy
= rc
.top
+ ((input
->u
.mi
.dy
* (rc
.bottom
- rc
.top
)) >> 16);
153 input
->u
.mi
.dx
= (input
->u
.mi
.dx
* GetSystemMetrics( SM_CXSCREEN
)) >> 16;
154 input
->u
.mi
.dy
= (input
->u
.mi
.dy
* GetSystemMetrics( SM_CYSCREEN
)) >> 16;
156 SetThreadDpiAwarenessContext( context
);
162 /* dx and dy can be negative numbers for relative movements */
163 SystemParametersInfoW(SPI_GETMOUSE
, 0, accel
, 0);
165 if (!accel
[2]) return;
167 if (abs(input
->u
.mi
.dx
) > accel
[0])
170 if ((abs(input
->u
.mi
.dx
) > accel
[1]) && (accel
[2] == 2)) input
->u
.mi
.dx
*= 2;
172 if (abs(input
->u
.mi
.dy
) > accel
[0])
175 if ((abs(input
->u
.mi
.dy
) > accel
[1]) && (accel
[2] == 2)) input
->u
.mi
.dy
*= 2;
180 /***********************************************************************
181 * SendInput (USER32.@)
183 UINT WINAPI
SendInput( UINT count
, LPINPUT inputs
, int size
)
188 for (i
= 0; i
< count
; i
++)
190 if (inputs
[i
].type
== INPUT_MOUSE
)
192 /* we need to update the coordinates to what the server expects */
193 INPUT input
= inputs
[i
];
194 update_mouse_coords( &input
);
195 status
= send_hardware_message( 0, &input
, SEND_HWMSG_INJECTED
);
197 else status
= send_hardware_message( 0, &inputs
[i
], SEND_HWMSG_INJECTED
);
201 SetLastError( RtlNtStatusToDosError(status
) );
210 /***********************************************************************
211 * keybd_event (USER32.@)
213 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
214 DWORD dwFlags
, ULONG_PTR dwExtraInfo
)
218 input
.type
= INPUT_KEYBOARD
;
219 input
.u
.ki
.wVk
= bVk
;
220 input
.u
.ki
.wScan
= bScan
;
221 input
.u
.ki
.dwFlags
= dwFlags
;
223 input
.u
.ki
.dwExtraInfo
= dwExtraInfo
;
224 SendInput( 1, &input
, sizeof(input
) );
228 /***********************************************************************
229 * mouse_event (USER32.@)
231 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
232 DWORD dwData
, ULONG_PTR dwExtraInfo
)
236 input
.type
= INPUT_MOUSE
;
239 input
.u
.mi
.mouseData
= dwData
;
240 input
.u
.mi
.dwFlags
= dwFlags
;
242 input
.u
.mi
.dwExtraInfo
= dwExtraInfo
;
243 SendInput( 1, &input
, sizeof(input
) );
247 /***********************************************************************
248 * GetCursorPos (USER32.@)
250 BOOL WINAPI DECLSPEC_HOTPATCH
GetCursorPos( POINT
*pt
)
256 if (!pt
) return FALSE
;
258 SERVER_START_REQ( set_cursor
)
260 if ((ret
= !wine_server_call( req
)))
262 pt
->x
= reply
->new_x
;
263 pt
->y
= reply
->new_y
;
264 last_change
= reply
->last_change
;
269 /* query new position from graphics driver if we haven't updated recently */
270 if (ret
&& GetTickCount() - last_change
> 100) ret
= USER_Driver
->pGetCursorPos( pt
);
271 if (ret
&& (dpi
= get_thread_dpi()))
273 DPI_AWARENESS_CONTEXT context
;
274 context
= SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
275 *pt
= map_dpi_point( *pt
, get_monitor_dpi( MonitorFromPoint( *pt
, MONITOR_DEFAULTTOPRIMARY
)), dpi
);
276 SetThreadDpiAwarenessContext( context
);
282 /***********************************************************************
283 * GetCursorInfo (USER32.@)
285 BOOL WINAPI
GetCursorInfo( PCURSORINFO pci
)
289 if (!pci
) return FALSE
;
291 SERVER_START_REQ( get_thread_input
)
294 if ((ret
= !wine_server_call( req
)))
296 pci
->hCursor
= wine_server_ptr_handle( reply
->cursor
);
297 pci
->flags
= (reply
->show_count
>= 0) ? CURSOR_SHOWING
: 0;
301 GetCursorPos(&pci
->ptScreenPos
);
306 /***********************************************************************
307 * SetCursorPos (USER32.@)
309 BOOL WINAPI DECLSPEC_HOTPATCH
SetCursorPos( INT x
, INT y
)
313 INT prev_x
, prev_y
, new_x
, new_y
;
316 if ((dpi
= get_thread_dpi()))
317 pt
= map_dpi_point( pt
, dpi
, get_monitor_dpi( MonitorFromPoint( pt
, MONITOR_DEFAULTTOPRIMARY
)));
319 SERVER_START_REQ( set_cursor
)
321 req
->flags
= SET_CURSOR_POS
;
324 if ((ret
= !wine_server_call( req
)))
326 prev_x
= reply
->prev_x
;
327 prev_y
= reply
->prev_y
;
328 new_x
= reply
->new_x
;
329 new_y
= reply
->new_y
;
333 if (ret
&& (prev_x
!= new_x
|| prev_y
!= new_y
)) USER_Driver
->pSetCursorPos( new_x
, new_y
);
337 /**********************************************************************
338 * SetCapture (USER32.@)
340 HWND WINAPI DECLSPEC_HOTPATCH
SetCapture( HWND hwnd
)
344 set_capture_window( hwnd
, 0, &previous
);
349 /**********************************************************************
350 * ReleaseCapture (USER32.@)
352 BOOL WINAPI DECLSPEC_HOTPATCH
ReleaseCapture(void)
354 BOOL ret
= set_capture_window( 0, 0, NULL
);
356 /* Somebody may have missed some mouse movements */
357 if (ret
) mouse_event( MOUSEEVENTF_MOVE
, 0, 0, 0, 0 );
363 /**********************************************************************
364 * GetCapture (USER32.@)
366 HWND WINAPI
GetCapture(void)
370 SERVER_START_REQ( get_thread_input
)
372 req
->tid
= GetCurrentThreadId();
373 if (!wine_server_call_err( req
)) ret
= wine_server_ptr_handle( reply
->capture
);
380 static void check_for_events( UINT flags
)
382 if (USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, flags
, 0 ) == WAIT_TIMEOUT
)
383 flush_window_surfaces( TRUE
);
386 /**********************************************************************
387 * GetAsyncKeyState (USER32.@)
389 * Determine if a key is or was pressed. retval has high-order
390 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
393 SHORT WINAPI DECLSPEC_HOTPATCH
GetAsyncKeyState( INT key
)
395 struct user_key_state_info
*key_state_info
= get_user_thread_info()->key_state
;
396 INT counter
= global_key_state_counter
;
400 if (key
< 0 || key
>= 256) return 0;
402 check_for_events( QS_INPUT
);
404 if ((ret
= USER_Driver
->pGetAsyncKeyState( key
)) == -1)
406 if (key_state_info
&&
407 !(key_state_info
->state
[key
] & 0xc0) &&
408 key_state_info
->counter
== counter
&&
409 GetTickCount() - key_state_info
->time
< 50)
411 /* use cached value */
414 else if (!key_state_info
)
416 key_state_info
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*key_state_info
) );
417 get_user_thread_info()->key_state
= key_state_info
;
421 SERVER_START_REQ( get_key_state
)
427 prev_key_state
= key_state_info
->state
[key
];
428 wine_server_set_reply( req
, key_state_info
->state
, sizeof(key_state_info
->state
) );
430 if (!wine_server_call( req
))
432 if (reply
->state
& 0x40) ret
|= 0x0001;
433 if (reply
->state
& 0x80) ret
|= 0x8000;
436 /* force refreshing the key state cache - some multithreaded programs
437 * (like Adobe Photoshop CS5) expect that changes to the async key state
438 * are also immediately available in other threads. */
439 if (prev_key_state
!= key_state_info
->state
[key
])
440 counter
= interlocked_xchg_add( &global_key_state_counter
, 1 ) + 1;
442 key_state_info
->time
= GetTickCount();
443 key_state_info
->counter
= counter
;
453 /***********************************************************************
454 * GetQueueStatus (USER32.@)
456 DWORD WINAPI
GetQueueStatus( UINT flags
)
460 if (flags
& ~(QS_ALLINPUT
| QS_ALLPOSTMESSAGE
| QS_SMRESULT
))
462 SetLastError( ERROR_INVALID_FLAGS
);
466 check_for_events( flags
);
468 SERVER_START_REQ( get_queue_status
)
470 req
->clear_bits
= flags
;
471 wine_server_call( req
);
472 ret
= MAKELONG( reply
->changed_bits
& flags
, reply
->wake_bits
& flags
);
479 /***********************************************************************
480 * GetInputState (USER32.@)
482 BOOL WINAPI
GetInputState(void)
486 check_for_events( QS_INPUT
);
488 SERVER_START_REQ( get_queue_status
)
491 wine_server_call( req
);
492 ret
= reply
->wake_bits
& (QS_KEY
| QS_MOUSEBUTTON
);
499 /******************************************************************
500 * GetLastInputInfo (USER32.@)
502 BOOL WINAPI
GetLastInputInfo(PLASTINPUTINFO plii
)
508 if (plii
->cbSize
!= sizeof (*plii
) )
510 SetLastError(ERROR_INVALID_PARAMETER
);
514 SERVER_START_REQ( get_last_input_time
)
516 ret
= !wine_server_call_err( req
);
518 plii
->dwTime
= reply
->time
;
525 /**********************************************************************
526 * AttachThreadInput (USER32.@)
528 * Attaches the input processing mechanism of one thread to that of
531 BOOL WINAPI
AttachThreadInput( DWORD from
, DWORD to
, BOOL attach
)
535 SERVER_START_REQ( attach_thread_input
)
537 req
->tid_from
= from
;
539 req
->attach
= attach
;
540 ret
= !wine_server_call_err( req
);
547 /**********************************************************************
548 * GetKeyState (USER32.@)
550 * An application calls the GetKeyState function in response to a
551 * keyboard-input message. This function retrieves the state of the key
552 * at the time the input message was generated.
554 SHORT WINAPI DECLSPEC_HOTPATCH
GetKeyState(INT vkey
)
558 SERVER_START_REQ( get_key_state
)
560 req
->tid
= GetCurrentThreadId();
562 if (!wine_server_call( req
)) retval
= (signed char)reply
->state
;
565 TRACE("key (0x%x) -> %x\n", vkey
, retval
);
570 /**********************************************************************
571 * GetKeyboardState (USER32.@)
573 BOOL WINAPI DECLSPEC_HOTPATCH
GetKeyboardState( LPBYTE state
)
577 TRACE("(%p)\n", state
);
579 memset( state
, 0, 256 );
580 SERVER_START_REQ( get_key_state
)
582 req
->tid
= GetCurrentThreadId();
584 wine_server_set_reply( req
, state
, 256 );
585 ret
= !wine_server_call_err( req
);
592 /**********************************************************************
593 * SetKeyboardState (USER32.@)
595 BOOL WINAPI
SetKeyboardState( LPBYTE state
)
599 SERVER_START_REQ( set_key_state
)
601 req
->tid
= GetCurrentThreadId();
602 wine_server_add_data( req
, state
, 256 );
603 ret
= !wine_server_call_err( req
);
610 /**********************************************************************
611 * VkKeyScanA (USER32.@)
613 * VkKeyScan translates an ANSI character to a virtual-key and shift code
614 * for the current keyboard.
615 * high-order byte yields :
619 * 3-5 Shift-key combinations that are not used for characters
622 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
623 * FIXME : works ok except for dead chars :
624 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
625 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
627 SHORT WINAPI
VkKeyScanA(CHAR cChar
)
631 if (IsDBCSLeadByte(cChar
)) return -1;
633 MultiByteToWideChar(CP_ACP
, 0, &cChar
, 1, &wChar
, 1);
634 return VkKeyScanW(wChar
);
637 /******************************************************************************
638 * VkKeyScanW (USER32.@)
640 SHORT WINAPI
VkKeyScanW(WCHAR cChar
)
642 return VkKeyScanExW(cChar
, GetKeyboardLayout(0));
645 /**********************************************************************
646 * VkKeyScanExA (USER32.@)
648 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
652 if (IsDBCSLeadByte(cChar
)) return -1;
654 MultiByteToWideChar(CP_ACP
, 0, &cChar
, 1, &wChar
, 1);
655 return VkKeyScanExW(wChar
, dwhkl
);
658 /******************************************************************************
659 * VkKeyScanExW (USER32.@)
661 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
663 return USER_Driver
->pVkKeyScanEx(cChar
, dwhkl
);
666 /**********************************************************************
667 * OemKeyScan (USER32.@)
669 DWORD WINAPI
OemKeyScan( WORD oem
)
673 char oem_char
= LOBYTE( oem
);
675 if (!OemToCharBuffW( &oem_char
, &wchr
, 1 ))
678 vkey
= VkKeyScanW( wchr
);
679 scan
= MapVirtualKeyW( LOBYTE( vkey
), MAPVK_VK_TO_VSC
);
680 if (!scan
) return -1;
687 /******************************************************************************
688 * GetKeyboardType (USER32.@)
690 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
692 TRACE_(keyboard
)("(%d)\n", nTypeFlag
);
693 if (LOWORD(GetKeyboardLayout(0)) == MAKELANGID(LANG_JAPANESE
, SUBLANG_JAPANESE_JAPAN
))
695 /* scan code for `_', the key left of r-shift, in Japanese 106 keyboard */
696 const UINT JP106_VSC_USCORE
= 0x73;
700 case 0: /* Keyboard type */
701 return 7; /* Japanese keyboard */
702 case 1: /* Keyboard Subtype */
703 /* Test keyboard mappings to detect Japanese keyboard */
704 if (MapVirtualKeyW(VK_OEM_102
, MAPVK_VK_TO_VSC
) == JP106_VSC_USCORE
705 && MapVirtualKeyW(JP106_VSC_USCORE
, MAPVK_VSC_TO_VK
) == VK_OEM_102
)
706 return 2; /* Japanese 106 */
708 return 0; /* AT-101 */
709 case 2: /* Number of F-keys */
710 return 12; /* It has 12 F-keys */
717 case 0: /* Keyboard type */
718 return 4; /* AT-101 */
719 case 1: /* Keyboard Subtype */
720 return 0; /* There are no defined subtypes */
721 case 2: /* Number of F-keys */
722 return 12; /* We're doing an 101 for now, so return 12 F-keys */
725 WARN_(keyboard
)("Unknown type\n");
726 return 0; /* The book says 0 here, so 0 */
729 /******************************************************************************
730 * MapVirtualKeyA (USER32.@)
732 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
734 return MapVirtualKeyExA( code
, maptype
, GetKeyboardLayout(0) );
737 /******************************************************************************
738 * MapVirtualKeyW (USER32.@)
740 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
742 return MapVirtualKeyExW(code
, maptype
, GetKeyboardLayout(0));
745 /******************************************************************************
746 * MapVirtualKeyExA (USER32.@)
748 UINT WINAPI
MapVirtualKeyExA(UINT code
, UINT maptype
, HKL hkl
)
752 ret
= MapVirtualKeyExW( code
, maptype
, hkl
);
753 if (maptype
== MAPVK_VK_TO_CHAR
)
758 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, (LPSTR
)&ch
, 1, NULL
, NULL
);
764 /******************************************************************************
765 * MapVirtualKeyExW (USER32.@)
767 UINT WINAPI
MapVirtualKeyExW(UINT code
, UINT maptype
, HKL hkl
)
769 TRACE_(keyboard
)("(%X, %d, %p)\n", code
, maptype
, hkl
);
771 return USER_Driver
->pMapVirtualKeyEx(code
, maptype
, hkl
);
774 /****************************************************************************
775 * GetKBCodePage (USER32.@)
777 UINT WINAPI
GetKBCodePage(void)
782 /***********************************************************************
783 * GetKeyboardLayout (USER32.@)
785 * - device handle for keyboard layout defaulted to
786 * the language id. This is the way Windows default works.
787 * - the thread identifier is also ignored.
789 HKL WINAPI
GetKeyboardLayout(DWORD thread_id
)
791 return USER_Driver
->pGetKeyboardLayout(thread_id
);
794 /****************************************************************************
795 * GetKeyboardLayoutNameA (USER32.@)
797 BOOL WINAPI
GetKeyboardLayoutNameA(LPSTR pszKLID
)
799 WCHAR buf
[KL_NAMELENGTH
];
801 if (GetKeyboardLayoutNameW(buf
))
802 return WideCharToMultiByte( CP_ACP
, 0, buf
, -1, pszKLID
, KL_NAMELENGTH
, NULL
, NULL
) != 0;
806 /****************************************************************************
807 * GetKeyboardLayoutNameW (USER32.@)
809 BOOL WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
813 SetLastError(ERROR_NOACCESS
);
816 return USER_Driver
->pGetKeyboardLayoutName(pwszKLID
);
819 /****************************************************************************
820 * GetKeyNameTextA (USER32.@)
822 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
827 if (!nSize
|| !GetKeyNameTextW(lParam
, buf
, 256))
832 ret
= WideCharToMultiByte(CP_ACP
, 0, buf
, -1, lpBuffer
, nSize
, NULL
, NULL
);
843 /****************************************************************************
844 * GetKeyNameTextW (USER32.@)
846 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
848 if (!lpBuffer
|| !nSize
) return 0;
849 return USER_Driver
->pGetKeyNameText( lParam
, lpBuffer
, nSize
);
852 /****************************************************************************
853 * ToUnicode (USER32.@)
855 INT WINAPI
ToUnicode(UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
856 LPWSTR lpwStr
, int size
, UINT flags
)
858 return ToUnicodeEx(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
, GetKeyboardLayout(0));
861 /****************************************************************************
862 * ToUnicodeEx (USER32.@)
864 INT WINAPI
ToUnicodeEx(UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
865 LPWSTR lpwStr
, int size
, UINT flags
, HKL hkl
)
867 if (!lpKeyState
) return 0;
868 return USER_Driver
->pToUnicodeEx(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
, hkl
);
871 /****************************************************************************
874 INT WINAPI
ToAscii( UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
875 LPWORD lpChar
, UINT flags
)
877 return ToAsciiEx(virtKey
, scanCode
, lpKeyState
, lpChar
, flags
, GetKeyboardLayout(0));
880 /****************************************************************************
881 * ToAsciiEx (USER32.@)
883 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
884 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
889 ret
= ToUnicodeEx(virtKey
, scanCode
, lpKeyState
, uni_chars
, 2, flags
, dwhkl
);
890 if (ret
< 0) n_ret
= 1; /* FIXME: make ToUnicode return 2 for dead chars */
892 WideCharToMultiByte(CP_ACP
, 0, uni_chars
, n_ret
, (LPSTR
)lpChar
, 2, NULL
, NULL
);
896 /**********************************************************************
897 * ActivateKeyboardLayout (USER32.@)
899 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
901 TRACE_(keyboard
)("(%p, %d)\n", hLayout
, flags
);
903 return USER_Driver
->pActivateKeyboardLayout(hLayout
, flags
);
906 /**********************************************************************
907 * BlockInput (USER32.@)
909 BOOL WINAPI
BlockInput(BOOL fBlockIt
)
911 FIXME_(keyboard
)("(%d): stub\n", fBlockIt
);
912 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
917 /***********************************************************************
918 * GetKeyboardLayoutList (USER32.@)
920 * Return number of values available if either input parm is
921 * 0, per MS documentation.
923 UINT WINAPI
GetKeyboardLayoutList(INT nBuff
, HKL
*layouts
)
925 TRACE_(keyboard
)( "(%d, %p)\n", nBuff
, layouts
);
927 return USER_Driver
->pGetKeyboardLayoutList( nBuff
, layouts
);
931 /***********************************************************************
932 * RegisterHotKey (USER32.@)
934 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
)
939 TRACE_(keyboard
)("(%p,%d,0x%08x,%X)\n",hwnd
,id
,modifiers
,vk
);
941 if ((hwnd
== NULL
|| WIN_IsCurrentThread(hwnd
)) &&
942 !USER_Driver
->pRegisterHotKey(hwnd
, modifiers
, vk
))
945 SERVER_START_REQ( register_hotkey
)
947 req
->window
= wine_server_user_handle( hwnd
);
949 req
->flags
= modifiers
;
951 if ((ret
= !wine_server_call_err( req
)))
953 replaced
= reply
->replaced
;
954 modifiers
= reply
->flags
;
961 USER_Driver
->pUnregisterHotKey(hwnd
, modifiers
, vk
);
966 /***********************************************************************
967 * UnregisterHotKey (USER32.@)
969 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
)
974 TRACE_(keyboard
)("(%p,%d)\n",hwnd
,id
);
976 SERVER_START_REQ( unregister_hotkey
)
978 req
->window
= wine_server_user_handle( hwnd
);
980 if ((ret
= !wine_server_call_err( req
)))
982 modifiers
= reply
->flags
;
989 USER_Driver
->pUnregisterHotKey(hwnd
, modifiers
, vk
);
994 /***********************************************************************
995 * LoadKeyboardLayoutW (USER32.@)
997 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
999 TRACE_(keyboard
)("(%s, %d)\n", debugstr_w(pwszKLID
), Flags
);
1001 return USER_Driver
->pLoadKeyboardLayout(pwszKLID
, Flags
);
1004 /***********************************************************************
1005 * LoadKeyboardLayoutA (USER32.@)
1007 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
1010 UNICODE_STRING pwszKLIDW
;
1012 if (pwszKLID
) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW
, pwszKLID
);
1013 else pwszKLIDW
.Buffer
= NULL
;
1015 ret
= LoadKeyboardLayoutW(pwszKLIDW
.Buffer
, Flags
);
1016 RtlFreeUnicodeString(&pwszKLIDW
);
1021 /***********************************************************************
1022 * UnloadKeyboardLayout (USER32.@)
1024 BOOL WINAPI
UnloadKeyboardLayout(HKL hkl
)
1026 TRACE_(keyboard
)("(%p)\n", hkl
);
1028 return USER_Driver
->pUnloadKeyboardLayout(hkl
);
1031 typedef struct __TRACKINGLIST
{
1032 TRACKMOUSEEVENT tme
;
1033 POINT pos
; /* center of hover rectangle */
1036 /* FIXME: move tracking stuff into a per thread data */
1037 static _TRACKINGLIST tracking_info
;
1038 static UINT_PTR timer
;
1040 static void check_mouse_leave(HWND hwnd
, int hittest
)
1042 if (tracking_info
.tme
.hwndTrack
!= hwnd
)
1044 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
1045 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
1047 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
1049 /* remove the TME_LEAVE flag */
1050 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
1054 if (hittest
== HTCLIENT
)
1056 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
1058 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
1059 /* remove the TME_LEAVE flag */
1060 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
1065 if (!(tracking_info
.tme
.dwFlags
& TME_NONCLIENT
))
1067 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
1068 /* remove the TME_LEAVE flag */
1069 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
1075 static void CALLBACK
TrackMouseEventProc(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
,
1079 INT hoverwidth
= 0, hoverheight
= 0, hittest
;
1081 TRACE("hwnd %p, msg %04x, id %04lx, time %u\n", hwnd
, uMsg
, idEvent
, dwTime
);
1084 hwnd
= WINPOS_WindowFromPoint(hwnd
, pos
, &hittest
);
1086 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos
), hwnd
, hittest
);
1088 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH
, 0, &hoverwidth
, 0);
1089 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT
, 0, &hoverheight
, 0);
1091 TRACE("tracked pos %s, current pos %s, hover width %d, hover height %d\n",
1092 wine_dbgstr_point(&tracking_info
.pos
), wine_dbgstr_point(&pos
),
1093 hoverwidth
, hoverheight
);
1095 /* see if this tracking event is looking for TME_LEAVE and that the */
1096 /* mouse has left the window */
1097 if (tracking_info
.tme
.dwFlags
& TME_LEAVE
)
1099 check_mouse_leave(hwnd
, hittest
);
1102 if (tracking_info
.tme
.hwndTrack
!= hwnd
)
1104 /* mouse is gone, stop tracking mouse hover */
1105 tracking_info
.tme
.dwFlags
&= ~TME_HOVER
;
1108 /* see if we are tracking hovering for this hwnd */
1109 if (tracking_info
.tme
.dwFlags
& TME_HOVER
)
1111 /* has the cursor moved outside the rectangle centered around pos? */
1112 if ((abs(pos
.x
- tracking_info
.pos
.x
) > (hoverwidth
/ 2)) ||
1113 (abs(pos
.y
- tracking_info
.pos
.y
) > (hoverheight
/ 2)))
1115 /* record this new position as the current position */
1116 tracking_info
.pos
= pos
;
1120 if (hittest
== HTCLIENT
)
1122 ScreenToClient(hwnd
, &pos
);
1123 TRACE("client cursor pos %s\n", wine_dbgstr_point(&pos
));
1125 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSEHOVER
,
1126 get_key_state(), MAKELPARAM( pos
.x
, pos
.y
));
1130 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
1131 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSEHOVER
,
1132 hittest
, MAKELPARAM( pos
.x
, pos
.y
));
1135 /* stop tracking mouse hover */
1136 tracking_info
.tme
.dwFlags
&= ~TME_HOVER
;
1140 /* stop the timer if the tracking list is empty */
1141 if (!(tracking_info
.tme
.dwFlags
& (TME_HOVER
| TME_LEAVE
)))
1143 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1145 tracking_info
.tme
.hwndTrack
= 0;
1146 tracking_info
.tme
.dwFlags
= 0;
1147 tracking_info
.tme
.dwHoverTime
= 0;
1152 /***********************************************************************
1153 * TrackMouseEvent [USER32]
1155 * Requests notification of mouse events
1157 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1158 * to the hwnd specified in the ptme structure. After the event message
1159 * is posted to the hwnd, the entry in the queue is removed.
1161 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1162 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1163 * immediately and the TME_LEAVE flag being ignored.
1166 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1175 TrackMouseEvent (TRACKMOUSEEVENT
*ptme
)
1182 TRACE("%x, %x, %p, %u\n", ptme
->cbSize
, ptme
->dwFlags
, ptme
->hwndTrack
, ptme
->dwHoverTime
);
1184 if (ptme
->cbSize
!= sizeof(TRACKMOUSEEVENT
)) {
1185 WARN("wrong TRACKMOUSEEVENT size from app\n");
1186 SetLastError(ERROR_INVALID_PARAMETER
);
1190 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1191 if (ptme
->dwFlags
& TME_QUERY
)
1193 *ptme
= tracking_info
.tme
;
1194 /* set cbSize in the case it's not initialized yet */
1195 ptme
->cbSize
= sizeof(TRACKMOUSEEVENT
);
1197 return TRUE
; /* return here, TME_QUERY is retrieving information */
1200 if (!IsWindow(ptme
->hwndTrack
))
1202 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1206 hover_time
= (ptme
->dwFlags
& TME_HOVER
) ? ptme
->dwHoverTime
: HOVER_DEFAULT
;
1208 /* if HOVER_DEFAULT was specified replace this with the system's current value.
1209 * TME_LEAVE doesn't need to specify hover time so use default */
1210 if (hover_time
== HOVER_DEFAULT
|| hover_time
== 0)
1211 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME
, 0, &hover_time
, 0);
1214 hwnd
= WINPOS_WindowFromPoint(ptme
->hwndTrack
, pos
, &hittest
);
1215 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos
), hwnd
, hittest
);
1217 if (ptme
->dwFlags
& ~(TME_CANCEL
| TME_HOVER
| TME_LEAVE
| TME_NONCLIENT
))
1218 FIXME("Unknown flag(s) %08x\n", ptme
->dwFlags
& ~(TME_CANCEL
| TME_HOVER
| TME_LEAVE
| TME_NONCLIENT
));
1220 if (ptme
->dwFlags
& TME_CANCEL
)
1222 if (tracking_info
.tme
.hwndTrack
== ptme
->hwndTrack
)
1224 tracking_info
.tme
.dwFlags
&= ~(ptme
->dwFlags
& ~TME_CANCEL
);
1226 /* if we aren't tracking on hover or leave remove this entry */
1227 if (!(tracking_info
.tme
.dwFlags
& (TME_HOVER
| TME_LEAVE
)))
1229 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1231 tracking_info
.tme
.hwndTrack
= 0;
1232 tracking_info
.tme
.dwFlags
= 0;
1233 tracking_info
.tme
.dwHoverTime
= 0;
1237 /* In our implementation it's possible that another window will receive a
1238 * WM_MOUSEMOVE and call TrackMouseEvent before TrackMouseEventProc is
1239 * called. In such a situation post the WM_MOUSELEAVE now */
1240 if (tracking_info
.tme
.dwFlags
& TME_LEAVE
&& tracking_info
.tme
.hwndTrack
!= NULL
)
1241 check_mouse_leave(hwnd
, hittest
);
1245 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1247 tracking_info
.tme
.hwndTrack
= 0;
1248 tracking_info
.tme
.dwFlags
= 0;
1249 tracking_info
.tme
.dwHoverTime
= 0;
1252 if (ptme
->hwndTrack
== hwnd
)
1254 /* Adding new mouse event to the tracking list */
1255 tracking_info
.tme
= *ptme
;
1256 tracking_info
.tme
.dwHoverTime
= hover_time
;
1258 /* Initialize HoverInfo variables even if not hover tracking */
1259 tracking_info
.pos
= pos
;
1261 timer
= SetSystemTimer(tracking_info
.tme
.hwndTrack
, (UINT_PTR
)&tracking_info
.tme
, hover_time
, TrackMouseEventProc
);
1268 /***********************************************************************
1269 * GetMouseMovePointsEx [USER32]
1272 * Success: count of point set in the buffer
1275 int WINAPI
GetMouseMovePointsEx(UINT size
, LPMOUSEMOVEPOINT ptin
, LPMOUSEMOVEPOINT ptout
, int count
, DWORD res
) {
1277 if((size
!= sizeof(MOUSEMOVEPOINT
)) || (count
< 0) || (count
> 64)) {
1278 SetLastError(ERROR_INVALID_PARAMETER
);
1282 if(!ptin
|| (!ptout
&& count
)) {
1283 SetLastError(ERROR_NOACCESS
);
1287 FIXME("(%d %p %p %d %d) stub\n", size
, ptin
, ptout
, count
, res
);
1289 SetLastError(ERROR_POINT_NOT_FOUND
);
1293 /***********************************************************************
1294 * EnableMouseInPointer (USER32.@)
1296 BOOL WINAPI
EnableMouseInPointer(BOOL enable
)
1298 FIXME("(%#x) stub\n", enable
);
1300 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);