3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * PROJECT: ReactOS user32.dll
21 * FILE: win32ss/user/user32/windows/input.c
23 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * 09-05-2001 CSH Created
32 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
43 return NtUserDragDetect(hWnd
, pt
);
48 ULONG dx
= GetSystemMetrics(SM_CXDRAG
);
49 ULONG dy
= GetSystemMetrics(SM_CYDRAG
);
51 rect
.left
= pt
.x
- dx
;
52 rect
.right
= pt
.x
+ dx
;
54 rect
.bottom
= pt
.y
+ dy
;
61 PeekMessageW(&msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_REMOVE
) ||
62 PeekMessageW(&msg
, 0, WM_KEYFIRST
, WM_KEYLAST
, PM_REMOVE
)
65 if (msg
.message
== WM_LBUTTONUP
)
70 if (msg
.message
== WM_MOUSEMOVE
)
72 tmp
.x
= LOWORD(msg
.lParam
);
73 tmp
.y
= HIWORD(msg
.lParam
);
74 if (!PtInRect(&rect
, tmp
))
80 if (msg
.message
== WM_KEYDOWN
)
82 if (msg
.wParam
== VK_ESCAPE
)
99 EnableWindow(HWND hWnd
, BOOL bEnable
)
101 return NtUserxEnableWindow(hWnd
, bEnable
);
110 GetAsyncKeyState(int vKey
)
112 if (vKey
< 0 || vKey
> 256)
114 return (SHORT
)NtUserGetAsyncKeyState((DWORD
)vKey
);
122 GetKeyboardLayout(DWORD idThread
)
124 return NtUserxGetKeyboardLayout(idThread
);
142 GetKeyNameTextA(LONG lParam
,
149 BOOL defChar
= FALSE
;
151 pwszBuf
= HeapAlloc(GetProcessHeap(), 0, nSize
* sizeof(WCHAR
));
155 cchBuf
= NtUserGetKeyNameText(lParam
, pwszBuf
, nSize
);
157 iRet
= WideCharToMultiByte(CP_ACP
, 0,
159 lpString
, nSize
, ".", &defChar
); // FIXME: do we need defChar?
161 HeapFree(GetProcessHeap(), 0, pwszBuf
);
170 GetKeyNameTextW(LONG lParam
,
174 return NtUserGetKeyNameText(lParam
, lpString
, nSize
);
183 GetKeyState(int nVirtKey
)
185 return (SHORT
)NtUserGetKeyState((DWORD
)nVirtKey
);
192 GetKeyboardLayoutNameA(LPSTR pwszKLID
)
194 WCHAR buf
[KL_NAMELENGTH
];
196 if (!GetKeyboardLayoutNameW(buf
))
199 if (!WideCharToMultiByte(CP_ACP
, 0, buf
, -1, pwszKLID
, KL_NAMELENGTH
, NULL
, NULL
))
209 GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
211 return NtUserGetKeyboardLayoutName(pwszKLID
);
218 GetKeyboardType(int nTypeFlag
)
220 return NtUserxGetKeyboardType(nTypeFlag
);
227 GetLastInputInfo(PLASTINPUTINFO plii
)
231 if (plii
->cbSize
!= sizeof (*plii
))
233 SetLastError(ERROR_INVALID_PARAMETER
);
237 plii
->dwTime
= gpsi
->dwLastRITEventTickCount
;
245 LoadKeyboardLayoutA(LPCSTR pszKLID
,
250 if (!MultiByteToWideChar(CP_ACP
, 0, pszKLID
, -1,
251 wszKLID
, sizeof(wszKLID
)/sizeof(wszKLID
[0])))
256 return LoadKeyboardLayoutW(wszKLID
, Flags
);
263 LoadKeyboardLayoutW(LPCWSTR pwszKLID
,
266 DWORD dwhkl
, dwType
, dwSize
;
267 UNICODE_STRING ustrKbdName
;
268 UNICODE_STRING ustrKLID
;
269 WCHAR wszRegKey
[256] = L
"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts\\";
270 WCHAR wszLayoutId
[10], wszNewKLID
[10];
273 /* LOWORD of dwhkl is Locale Identifier */
274 dwhkl
= LOWORD(wcstoul(pwszKLID
, NULL
, 16));
276 if (Flags
& KLF_SUBSTITUTE_OK
)
278 /* Check substitutes key */
279 if (RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Keyboard Layout\\Substitutes", 0,
280 KEY_READ
, &hKey
) == ERROR_SUCCESS
)
282 dwSize
= sizeof(wszNewKLID
);
283 if (RegQueryValueExW(hKey
, pwszKLID
, NULL
, &dwType
, (LPBYTE
)wszNewKLID
, &dwSize
) == ERROR_SUCCESS
)
285 /* Use new KLID value */
286 pwszKLID
= wszNewKLID
;
289 /* Close the key now */
294 /* Append KLID at the end of registry key */
295 StringCbCatW(wszRegKey
, sizeof(wszRegKey
), pwszKLID
);
297 /* Open layout registry key for read */
298 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, wszRegKey
, 0,
299 KEY_READ
, &hKey
) == ERROR_SUCCESS
)
301 dwSize
= sizeof(wszLayoutId
);
302 if (RegQueryValueExW(hKey
, L
"Layout Id", NULL
, &dwType
, (LPBYTE
)wszLayoutId
, &dwSize
) == ERROR_SUCCESS
)
304 /* If Layout Id is specified, use this value | f000 as HIWORD */
305 /* FIXME: Microsoft Office expects this value to be something specific
306 * for Japanese and Korean Windows with an IME the value is 0xe001
307 * We should probably check to see if an IME exists and if so then
308 * set this word properly.
310 dwhkl
|= (0xf000 | wcstol(wszLayoutId
, NULL
, 16)) << 16;
313 /* Close the key now */
318 ERR("Could not find keyboard layout %S.\n", pwszKLID
);
322 /* If Layout Id is not given HIWORD == LOWORD (for dwhkl) */
324 dwhkl
|= dwhkl
<< 16;
326 ZeroMemory(&ustrKbdName
, sizeof(ustrKbdName
));
327 RtlInitUnicodeString(&ustrKLID
, pwszKLID
);
328 return NtUserLoadKeyboardLayoutEx(NULL
, 0, &ustrKbdName
,
337 MapVirtualKeyA(UINT uCode
,
340 return MapVirtualKeyExA(uCode
, uMapType
, GetKeyboardLayout(0));
347 MapVirtualKeyExA(UINT uCode
,
351 return MapVirtualKeyExW(uCode
, uMapType
, dwhkl
);
359 MapVirtualKeyExW(UINT uCode
,
363 return NtUserMapVirtualKeyEx(uCode
, uMapType
, 0, dwhkl
);
371 MapVirtualKeyW(UINT uCode
,
374 return MapVirtualKeyExW(uCode
, uMapType
, GetKeyboardLayout(0));
382 OemKeyScan(WORD wOemChar
)
388 MultiByteToWideChar(CP_OEMCP
, 0, (PCSTR
)&wOemChar
, 1, &p
, 1);
390 Scan
= MapVirtualKeyW((Vk
& 0x00ff), 0);
391 if (!Scan
) return -1;
393 Page 450-1, MS W2k SuperBible by SAMS. Return, low word has the
394 scan code and high word has the shift state.
396 return ((Vk
& 0xff00) << 8) | Scan
;
404 SetDoubleClickTime(UINT uInterval
)
406 return (BOOL
)NtUserSystemParametersInfo(SPI_SETDOUBLECLICKTIME
,
421 return NtUserxSwapMouseButton(fSwap
);
429 ToAscii(UINT uVirtKey
,
431 CONST BYTE
*lpKeyState
,
435 return ToAsciiEx(uVirtKey
, uScanCode
, lpKeyState
, lpChar
, uFlags
, 0);
443 ToAsciiEx(UINT uVirtKey
,
445 CONST BYTE
*lpKeyState
,
453 Ret
= ToUnicodeEx(uVirtKey
, uScanCode
, lpKeyState
, UniChars
, 2, uFlags
, dwhkl
);
454 CharCount
= (Ret
< 0 ? 1 : Ret
);
455 WideCharToMultiByte(CP_ACP
, 0, UniChars
, CharCount
, (LPSTR
)lpChar
, 2, NULL
, NULL
);
465 ToUnicode(UINT wVirtKey
,
467 CONST BYTE
*lpKeyState
,
472 return ToUnicodeEx(wVirtKey
, wScanCode
, lpKeyState
, pwszBuff
, cchBuff
,
481 ToUnicodeEx(UINT wVirtKey
,
483 CONST BYTE
*lpKeyState
,
489 return NtUserToUnicodeEx(wVirtKey
, wScanCode
, (PBYTE
)lpKeyState
, pwszBuff
, cchBuff
,
503 if (IsDBCSLeadByte(ch
))
506 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wChar
, 1);
507 return VkKeyScanW(wChar
);
515 VkKeyScanExA(CHAR ch
,
520 if (IsDBCSLeadByte(ch
))
523 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wChar
, 1);
524 return VkKeyScanExW(wChar
, dwhkl
);
532 VkKeyScanExW(WCHAR ch
,
535 return (SHORT
)NtUserVkKeyScanEx(ch
, dwhkl
, TRUE
);
545 return (SHORT
)NtUserVkKeyScanEx(ch
, 0, FALSE
);
558 ULONG_PTR dwExtraInfo
)
562 Input
.type
= INPUT_KEYBOARD
;
564 Input
.ki
.wScan
= bScan
;
565 Input
.ki
.dwFlags
= dwFlags
;
567 Input
.ki
.dwExtraInfo
= dwExtraInfo
;
569 NtUserSendInput(1, &Input
, sizeof(INPUT
));
583 ULONG_PTR dwExtraInfo
)
587 Input
.type
= INPUT_MOUSE
;
590 Input
.mi
.mouseData
= dwData
;
591 Input
.mi
.dwFlags
= dwFlags
;
593 Input
.mi
.dwExtraInfo
= dwExtraInfo
;
595 NtUserSendInput(1, &Input
, sizeof(INPUT
));