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 ******************************************************************/
35 /* FUNCTIONS *****************************************************************/
48 return NtUserDragDetect(hWnd
, pt
.x
, pt
.y
);
53 ULONG dx
= NtUserGetSystemMetrics(SM_CXDRAG
);
54 ULONG dy
= NtUserGetSystemMetrics(SM_CYDRAG
);
56 rect
.left
= pt
.x
- dx
;
57 rect
.right
= pt
.x
+ dx
;
59 rect
.bottom
= pt
.y
+ dy
;
65 while (PeekMessageW(&msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_REMOVE
))
67 if (msg
.message
== WM_LBUTTONUP
)
72 if (msg
.message
== WM_MOUSEMOVE
)
74 tmp
.x
= LOWORD(msg
.lParam
);
75 tmp
.y
= HIWORD(msg
.lParam
);
76 if (!PtInRect(&rect
, tmp
))
94 ActivateKeyboardLayout(HKL hkl
,
106 BlockInput(BOOL fBlockIt
)
108 return NtUserBlockInput(fBlockIt
);
116 EnableWindow(HWND hWnd
,
119 LONG Style
= NtUserGetWindowLong(hWnd
, GWL_STYLE
, FALSE
);
120 Style
= bEnable
? Style
& ~WS_DISABLED
: Style
| WS_DISABLED
;
121 NtUserSetWindowLong(hWnd
, GWL_STYLE
, Style
, FALSE
);
123 SendMessageA(hWnd
, WM_ENABLE
, (LPARAM
) IsWindowEnabled(hWnd
), 0);
125 // Return nonzero if it was disabled, or zero if it wasn't:
126 return IsWindowEnabled(hWnd
);
134 GetAsyncKeyState(int vKey
)
146 GetDoubleClickTime(VOID
)
148 return NtUserGetDoubleClickTime();
156 GetKeyboardLayout(DWORD idThread
)
178 GetKeyNameTextA(LONG lParam
,
182 LPWSTR intermediateString
=
183 HeapAlloc(GetProcessHeap(),0,nSize
* sizeof(WCHAR
));
186 BOOL defChar
= FALSE
;
188 if( !intermediateString
) return 0;
189 ret
= GetKeyNameTextW(lParam
,intermediateString
,nSize
);
190 if( ret
== 0 ) { lpString
[0] = 0; return 0; }
192 wstrLen
= wcslen( intermediateString
);
193 ret
= WideCharToMultiByte(CP_ACP
, 0,
194 intermediateString
, wstrLen
,
195 lpString
, nSize
, ".", &defChar
);
197 HeapFree(GetProcessHeap(),0,intermediateString
);
206 GetKeyNameTextW(LONG lParam
,
210 return NtUserGetKeyNameText( lParam
, lpString
, nSize
);
218 GetKeyState(int nVirtKey
)
220 return (SHORT
) NtUserGetKeyState((DWORD
) nVirtKey
);
228 GetKeyboardLayoutList(int nBuff
,
240 GetKeyboardLayoutNameA(LPSTR pwszKLID
)
251 GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
262 GetKeyboardState(PBYTE lpKeyState
)
265 return (BOOL
) NtUserGetKeyboardState((LPBYTE
) lpKeyState
);
273 GetKeyboardType(int nTypeFlag
)
284 GetLastInputInfo(PLASTINPUTINFO plii
)
295 LoadKeyboardLayoutA(LPCSTR pwszKLID
,
307 LoadKeyboardLayoutW(LPCWSTR pwszKLID
,
319 MapVirtualKeyA(UINT uCode
,
322 return MapVirtualKeyExA( uCode
, uMapType
, GetKeyboardLayout( 0 ) );
330 MapVirtualKeyExA(UINT uCode
,
334 return MapVirtualKeyExW( uCode
, uMapType
, dwhkl
);
342 MapVirtualKeyExW(UINT uCode
,
346 return NtUserMapVirtualKeyEx( uCode
, uMapType
, 0, dwhkl
);
354 MapVirtualKeyW(UINT uCode
,
357 return MapVirtualKeyExW( uCode
, uMapType
, GetKeyboardLayout( 0 ) );
365 OemKeyScan(WORD wOemChar
)
376 RegisterHotKey(HWND hWnd
,
381 return (BOOL
)NtUserRegisterHotKey(hWnd
,
392 SetDoubleClickTime(UINT uInterval
)
394 return (BOOL
)NtUserSystemParametersInfo(SPI_SETDOUBLECLICKTIME
,
407 return NtUserSetFocus(hWnd
);
415 SetKeyboardState(LPBYTE lpKeyState
)
417 return (BOOL
) NtUserSetKeyboardState((LPBYTE
)lpKeyState
);
429 return NtUserSwapMouseButton(fSwap
);
437 ToAscii(UINT uVirtKey
,
439 CONST PBYTE lpKeyState
,
443 return ToAsciiEx(uVirtKey
, uScanCode
, lpKeyState
, lpChar
, uFlags
, 0);
451 ToAsciiEx(UINT uVirtKey
,
453 CONST PBYTE lpKeyState
,
461 Ret
= ToUnicodeEx(uVirtKey
, uScanCode
, lpKeyState
, UniChars
, 2, uFlags
, dwhkl
);
462 CharCount
= (Ret
< 0 ? 1 : Ret
);
463 WideCharToMultiByte(CP_ACP
, 0, UniChars
, CharCount
, (LPSTR
) lpChar
, 2, NULL
, NULL
);
473 ToUnicode(UINT wVirtKey
,
475 CONST PBYTE lpKeyState
,
480 return ToUnicodeEx( wVirtKey
, wScanCode
, lpKeyState
, pwszBuff
, cchBuff
,
489 ToUnicodeEx(UINT wVirtKey
,
491 CONST PBYTE lpKeyState
,
497 return NtUserToUnicodeEx( wVirtKey
, wScanCode
, lpKeyState
, pwszBuff
, cchBuff
,
506 UnloadKeyboardLayout(HKL hkl
)
517 UnregisterHotKey(HWND hWnd
,
520 return (BOOL
)NtUserUnregisterHotKey(hWnd
, id
);
532 if (IsDBCSLeadByte(ch
)) return -1;
534 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wChar
, 1);
535 return VkKeyScanW(wChar
);
543 VkKeyScanExA(CHAR ch
,
548 if (IsDBCSLeadByte(ch
)) return -1;
550 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wChar
, 1);
551 return VkKeyScanExW(wChar
, dwhkl
);
559 VkKeyScanExW(WCHAR ch
,
573 return VkKeyScanExW(ch
, GetKeyboardLayout(0));
587 return NtUserSendInput(nInputs
, pInputs
, cbSize
);
591 * Private call for CSRSS
595 PrivateCsrssRegisterPrimitive(VOID
)
597 NtUserCallNoParam(NOPARAM_ROUTINE_REGISTER_PRIMITIVE
);
601 * Another private call for CSRSS
605 PrivateCsrssAcquireOrReleaseInputOwnership(BOOL Release
)
607 NtUserAcquireOrReleaseInputOwnership(Release
);
619 ULONG_PTR dwExtraInfo
)
625 Input
.type
= INPUT_KEYBOARD
;
627 Input
.ki
.wScan
= bScan
;
628 Input
.ki
.dwFlags
= dwFlags
;
630 Input
.ki
.dwExtraInfo
= dwExtraInfo
;
632 NtUserSendInput(1, &Input
, sizeof(INPUT
));
646 ULONG_PTR dwExtraInfo
)
650 Input
.type
= INPUT_MOUSE
;
653 Input
.mi
.mouseData
= dwData
;
654 Input
.mi
.dwFlags
= dwFlags
;
656 Input
.mi
.dwExtraInfo
= dwExtraInfo
;
658 NtUserSendInput(1, &Input
, sizeof(INPUT
));