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.
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/input.c
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 09-05-2001 CSH Created
29 /* INCLUDES ******************************************************************/
33 /* FUNCTIONS *****************************************************************/
46 return NtUserDragDetect(hWnd
, pt
.x
, pt
.y
);
51 ULONG dx
= NtUserGetSystemMetrics(SM_CXDRAG
);
52 ULONG dy
= NtUserGetSystemMetrics(SM_CYDRAG
);
54 rect
.left
= pt
.x
- dx
;
55 rect
.right
= pt
.x
+ dx
;
57 rect
.bottom
= pt
.y
+ dy
;
63 while (PeekMessageW(&msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
, 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
))
92 ActivateKeyboardLayout(HKL hkl
,
104 BlockInput(BOOL fBlockIt
)
106 return NtUserBlockInput(fBlockIt
);
114 EnableWindow(HWND hWnd
,
117 LONG Style
= NtUserGetWindowLong(hWnd
, GWL_STYLE
, FALSE
);
118 Style
= bEnable
? Style
& ~WS_DISABLED
: Style
| WS_DISABLED
;
119 NtUserSetWindowLong(hWnd
, GWL_STYLE
, Style
, FALSE
);
121 SendMessageA(hWnd
, WM_ENABLE
, (LPARAM
) IsWindowEnabled(hWnd
), 0);
123 // Return nonzero if it was disabled, or zero if it wasn't:
124 return IsWindowEnabled(hWnd
);
132 GetAsyncKeyState(int vKey
)
144 GetDoubleClickTime(VOID
)
146 return NtUserGetDoubleClickTime();
154 GetKeyboardLayout(DWORD idThread
)
176 GetKeyNameTextA(LONG lParam
,
180 LPWSTR intermediateString
=
181 HeapAlloc(GetProcessHeap(),0,nSize
* sizeof(WCHAR
));
184 BOOL defChar
= FALSE
;
186 if( !intermediateString
) return 0;
187 ret
= GetKeyNameTextW(lParam
,intermediateString
,nSize
);
188 if( ret
== 0 ) { lpString
[0] = 0; return 0; }
190 wstrLen
= wcslen( intermediateString
);
191 ret
= WideCharToMultiByte(CP_ACP
, 0,
192 intermediateString
, wstrLen
,
193 lpString
, nSize
, ".", &defChar
);
195 HeapFree(GetProcessHeap(),0,intermediateString
);
204 GetKeyNameTextW(LONG lParam
,
208 return NtUserGetKeyNameText( lParam
, lpString
, nSize
);
216 GetKeyState(int nVirtKey
)
218 return (SHORT
) NtUserGetKeyState((DWORD
) nVirtKey
);
226 GetKeyboardLayoutList(int nBuff
,
238 GetKeyboardLayoutNameA(LPSTR pwszKLID
)
249 GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
260 GetKeyboardState(PBYTE lpKeyState
)
263 return (BOOL
) NtUserGetKeyboardState((LPBYTE
) lpKeyState
);
271 GetKeyboardType(int nTypeFlag
)
282 GetLastInputInfo(PLASTINPUTINFO plii
)
293 LoadKeyboardLayoutA(LPCSTR pwszKLID
,
305 LoadKeyboardLayoutW(LPCWSTR pwszKLID
,
317 MapVirtualKeyA(UINT uCode
,
320 return MapVirtualKeyExA( uCode
, uMapType
, GetKeyboardLayout( 0 ) );
328 MapVirtualKeyExA(UINT uCode
,
332 return MapVirtualKeyExW( uCode
, uMapType
, dwhkl
);
340 MapVirtualKeyExW(UINT uCode
,
344 return NtUserMapVirtualKeyEx( uCode
, uMapType
, 0, dwhkl
);
352 MapVirtualKeyW(UINT uCode
,
355 return MapVirtualKeyExW( uCode
, uMapType
, GetKeyboardLayout( 0 ) );
363 OemKeyScan(WORD wOemChar
)
374 RegisterHotKey(HWND hWnd
,
379 return (BOOL
)NtUserRegisterHotKey(hWnd
,
390 SetDoubleClickTime(UINT uInterval
)
392 return (BOOL
)NtUserSystemParametersInfo(SPI_SETDOUBLECLICKTIME
,
405 return NtUserSetFocus(hWnd
);
413 SetKeyboardState(LPBYTE lpKeyState
)
415 return (BOOL
) NtUserSetKeyboardState((LPBYTE
)lpKeyState
);
427 return NtUserSwapMouseButton(fSwap
);
435 ToAscii(UINT uVirtKey
,
437 CONST PBYTE lpKeyState
,
441 return ToAsciiEx(uVirtKey
, uScanCode
, lpKeyState
, lpChar
, uFlags
, 0);
449 ToAsciiEx(UINT uVirtKey
,
451 CONST PBYTE lpKeyState
,
459 Ret
= ToUnicodeEx(uVirtKey
, uScanCode
, lpKeyState
, UniChars
, 2, uFlags
, dwhkl
);
460 CharCount
= (Ret
< 0 ? 1 : Ret
);
461 WideCharToMultiByte(CP_ACP
, 0, UniChars
, CharCount
, (LPSTR
) lpChar
, 2, NULL
, NULL
);
471 ToUnicode(UINT wVirtKey
,
473 CONST PBYTE lpKeyState
,
478 return ToUnicodeEx( wVirtKey
, wScanCode
, lpKeyState
, pwszBuff
, cchBuff
,
487 ToUnicodeEx(UINT wVirtKey
,
489 CONST PBYTE lpKeyState
,
495 return NtUserToUnicodeEx( wVirtKey
, wScanCode
, lpKeyState
, pwszBuff
, cchBuff
,
504 UnloadKeyboardLayout(HKL hkl
)
515 UnregisterHotKey(HWND hWnd
,
518 return (BOOL
)NtUserUnregisterHotKey(hWnd
, id
);
530 if (IsDBCSLeadByte(ch
)) return -1;
532 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wChar
, 1);
533 return VkKeyScanW(wChar
);
541 VkKeyScanExA(CHAR ch
,
546 if (IsDBCSLeadByte(ch
)) return -1;
548 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wChar
, 1);
549 return VkKeyScanExW(wChar
, dwhkl
);
557 VkKeyScanExW(WCHAR ch
,
571 return VkKeyScanExW(ch
, GetKeyboardLayout(0));
585 return NtUserSendInput(nInputs
, pInputs
, cbSize
);
589 * Private call for CSRSS
593 PrivateCsrssRegisterPrimitive(VOID
)
595 NtUserCallNoParam(NOPARAM_ROUTINE_REGISTER_PRIMITIVE
);
599 * Another private call for CSRSS
603 PrivateCsrssAcquireOrReleaseInputOwnership(BOOL Release
)
605 NtUserAcquireOrReleaseInputOwnership(Release
);
617 ULONG_PTR dwExtraInfo
)
623 Input
.type
= INPUT_KEYBOARD
;
625 Input
.ki
.wScan
= bScan
;
626 Input
.ki
.dwFlags
= dwFlags
;
628 Input
.ki
.dwExtraInfo
= dwExtraInfo
;
630 NtUserSendInput(1, &Input
, sizeof(INPUT
));
644 ULONG_PTR dwExtraInfo
)
648 Input
.type
= INPUT_MOUSE
;
651 Input
.mi
.mouseData
= dwData
;
652 Input
.mi
.dwFlags
= dwFlags
;
654 Input
.mi
.dwExtraInfo
= dwExtraInfo
;
656 NtUserSendInput(1, &Input
, sizeof(INPUT
));