2003-05-18 17:16:18 +00:00
|
|
|
/*
|
2002-01-14 01:11:58 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2011-12-14 04:07:06 +00:00
|
|
|
* PROJECT: ReactOS Win32k subsystem
|
2011-10-14 18:41:06 +00:00
|
|
|
* PURPOSE: General input functions
|
2015-02-05 00:11:35 +00:00
|
|
|
* FILE: win32ss/user/ntuser/input.c
|
2011-10-05 14:09:51 +00:00
|
|
|
* PROGRAMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
|
|
|
|
* Rafal Harabien (rafalh@reactos.org)
|
2002-01-14 01:11:58 +00:00
|
|
|
*/
|
|
|
|
|
2010-04-26 13:58:46 +00:00
|
|
|
#include <win32k.h>
|
2011-08-21 12:38:52 +00:00
|
|
|
DBG_DEFAULT_CHANNEL(UserInput);
|
2005-06-29 07:09:25 +00:00
|
|
|
|
2002-01-14 01:11:58 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
2009-01-15 23:15:31 +00:00
|
|
|
PTHREADINFO ptiRawInput;
|
2010-05-20 21:07:53 +00:00
|
|
|
PKTIMER MasterTimer = NULL;
|
2009-10-10 04:40:36 +00:00
|
|
|
PATTACHINFO gpai = NULL;
|
2012-08-18 22:13:38 +00:00
|
|
|
INT paiCount = 0;
|
2013-10-14 06:19:48 +00:00
|
|
|
HANDLE ghKeyboardDevice = NULL;
|
2006-07-06 20:42:45 +00:00
|
|
|
|
2011-05-27 23:18:57 +00:00
|
|
|
static DWORD LastInputTick = 0;
|
2011-10-16 11:39:47 +00:00
|
|
|
static HANDLE ghMouseDevice;
|
2002-01-14 01:11:58 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
/*
|
|
|
|
* IntLastInputTick
|
|
|
|
*
|
|
|
|
* Updates or gets last input tick count
|
|
|
|
*/
|
2011-10-05 14:09:51 +00:00
|
|
|
static DWORD FASTCALL
|
|
|
|
IntLastInputTick(BOOL bUpdate)
|
2006-09-09 19:41:12 +00:00
|
|
|
{
|
2011-10-05 14:09:51 +00:00
|
|
|
if (bUpdate)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
2019-04-11 22:56:04 +00:00
|
|
|
LastInputTick = EngGetTickCount32();
|
2011-09-09 16:17:02 +00:00
|
|
|
if (gpsi) gpsi->dwLastRITEventTickCount = LastInputTick;
|
|
|
|
}
|
|
|
|
return LastInputTick;
|
2011-05-27 23:18:57 +00:00
|
|
|
}
|
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
/*
|
|
|
|
* DoTheScreenSaver
|
|
|
|
*
|
2023-08-22 13:20:29 +00:00
|
|
|
* Check if screensaver should be started and sends message to SAS window
|
2011-10-16 11:39:47 +00:00
|
|
|
*/
|
2011-10-05 14:09:51 +00:00
|
|
|
VOID FASTCALL
|
|
|
|
DoTheScreenSaver(VOID)
|
2011-05-27 23:18:57 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
DWORD Test, TO;
|
|
|
|
|
|
|
|
if (gspv.iScrSaverTimeout > 0) // Zero means Off.
|
|
|
|
{
|
2019-04-11 22:56:04 +00:00
|
|
|
Test = EngGetTickCount32();
|
2011-09-09 16:17:02 +00:00
|
|
|
Test = Test - LastInputTick;
|
|
|
|
TO = 1000 * gspv.iScrSaverTimeout;
|
|
|
|
if (Test > TO)
|
|
|
|
{
|
2013-09-01 23:58:37 +00:00
|
|
|
TRACE("Screensaver Message Start! Tick %lu Timeout %d \n", Test, gspv.iScrSaverTimeout);
|
2011-09-09 16:17:02 +00:00
|
|
|
|
|
|
|
if (ppiScrnSaver) // We are or we are not the screensaver, prevent reentry...
|
2011-05-27 23:18:57 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
if (!(ppiScrnSaver->W32PF_flags & W32PF_IDLESCREENSAVER))
|
|
|
|
{
|
|
|
|
ppiScrnSaver->W32PF_flags |= W32PF_IDLESCREENSAVER;
|
|
|
|
ERR("Screensaver is Idle\n");
|
|
|
|
}
|
2011-05-27 23:18:57 +00:00
|
|
|
}
|
|
|
|
else
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
|
|
|
PUSER_MESSAGE_QUEUE ForegroundQueue = IntGetFocusMessageQueue();
|
2012-04-23 18:51:48 +00:00
|
|
|
if (ForegroundQueue && ForegroundQueue->spwndActive)
|
2011-09-09 16:17:02 +00:00
|
|
|
UserPostMessage(hwndSAS, WM_LOGONNOTIFY, LN_START_SCREENSAVE, 1); // lParam 1 == Secure
|
|
|
|
else
|
|
|
|
UserPostMessage(hwndSAS, WM_LOGONNOTIFY, LN_START_SCREENSAVE, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-09-09 19:41:12 +00:00
|
|
|
}
|
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
/*
|
|
|
|
* OpenInputDevice
|
|
|
|
*
|
|
|
|
* Opens input device for asynchronous access
|
|
|
|
*/
|
|
|
|
static
|
2011-10-16 14:59:29 +00:00
|
|
|
NTSTATUS NTAPI
|
2011-10-16 11:39:47 +00:00
|
|
|
OpenInputDevice(PHANDLE pHandle, PFILE_OBJECT *ppObject, CONST WCHAR *pszDeviceName)
|
2003-12-14 14:05:47 +00:00
|
|
|
{
|
2011-10-16 11:39:47 +00:00
|
|
|
UNICODE_STRING DeviceName;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
2011-09-09 16:17:02 +00:00
|
|
|
NTSTATUS Status;
|
2011-10-16 11:39:47 +00:00
|
|
|
IO_STATUS_BLOCK Iosb;
|
2011-09-09 16:17:02 +00:00
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
RtlInitUnicodeString(&DeviceName, pszDeviceName);
|
2011-09-09 16:17:02 +00:00
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&DeviceName,
|
2015-10-16 14:04:19 +00:00
|
|
|
OBJ_KERNEL_HANDLE,
|
2011-09-09 16:17:02 +00:00
|
|
|
NULL,
|
|
|
|
NULL);
|
2011-10-16 11:39:47 +00:00
|
|
|
|
|
|
|
Status = ZwOpenFile(pHandle,
|
|
|
|
FILE_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&Iosb,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
if (NT_SUCCESS(Status) && ppObject)
|
|
|
|
{
|
|
|
|
Status = ObReferenceObjectByHandle(*pHandle, SYNCHRONIZE, NULL, KernelMode, (PVOID*)ppObject, NULL);
|
|
|
|
ASSERT(NT_SUCCESS(Status));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RawInputThreadMain
|
|
|
|
*
|
|
|
|
* Reads data from input devices and supports win32 timers
|
|
|
|
*/
|
|
|
|
VOID NTAPI
|
2015-09-04 00:11:49 +00:00
|
|
|
RawInputThreadMain(VOID)
|
2011-10-16 11:39:47 +00:00
|
|
|
{
|
|
|
|
NTSTATUS MouStatus = STATUS_UNSUCCESSFUL, KbdStatus = STATUS_UNSUCCESSFUL, Status;
|
|
|
|
IO_STATUS_BLOCK MouIosb, KbdIosb;
|
2013-10-14 06:19:48 +00:00
|
|
|
PFILE_OBJECT pKbdDevice = NULL, pMouDevice = NULL;
|
2011-11-24 12:38:26 +00:00
|
|
|
LARGE_INTEGER ByteOffset;
|
|
|
|
//LARGE_INTEGER WaitTimeout;
|
2015-10-16 15:30:35 +00:00
|
|
|
PVOID WaitObjects[4], pSignaledObject = NULL;
|
|
|
|
KWAIT_BLOCK WaitBlockArray[RTL_NUMBER_OF(WaitObjects)];
|
|
|
|
ULONG cWaitObjects = 0, cMaxWaitObjects = 2;
|
2011-10-16 11:39:47 +00:00
|
|
|
MOUSE_INPUT_DATA MouseInput;
|
|
|
|
KEYBOARD_INPUT_DATA KeyInput;
|
2015-10-16 15:30:35 +00:00
|
|
|
PVOID ShutdownEvent;
|
2018-12-16 11:16:29 +00:00
|
|
|
HWINSTA hWinSta;
|
2012-03-04 11:32:43 +00:00
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
ByteOffset.QuadPart = (LONGLONG)0;
|
2011-11-24 12:38:26 +00:00
|
|
|
//WaitTimeout.QuadPart = (LONGLONG)(-10000000);
|
2011-10-16 11:39:47 +00:00
|
|
|
|
2012-02-06 12:30:59 +00:00
|
|
|
ptiRawInput = GetW32ThreadInfo();
|
2011-10-16 11:39:47 +00:00
|
|
|
ptiRawInput->TIF_flags |= TIF_SYSTEMTHREAD;
|
2012-02-06 12:30:59 +00:00
|
|
|
ptiRawInput->pClientInfo->dwTIFlags = ptiRawInput->TIF_flags;
|
|
|
|
|
2013-09-01 23:58:37 +00:00
|
|
|
TRACE("Raw Input Thread %p\n", ptiRawInput);
|
2011-09-09 16:17:02 +00:00
|
|
|
|
|
|
|
KeSetPriorityThread(&PsGetCurrentThread()->Tcb,
|
|
|
|
LOW_REALTIME_PRIORITY + 3);
|
|
|
|
|
2018-12-16 11:16:29 +00:00
|
|
|
Status = ObOpenObjectByPointer(InputWindowStation,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
MAXIMUM_ALLOWED,
|
|
|
|
ExWindowStationObjectType,
|
|
|
|
UserMode,
|
|
|
|
(PHANDLE)&hWinSta);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
UserSetProcessWindowStation(hWinSta);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSERT(FALSE);
|
|
|
|
/* Failed to open the interactive winsta! What now? */
|
|
|
|
}
|
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
UserEnterExclusive();
|
|
|
|
StartTheTimers();
|
|
|
|
UserLeave();
|
|
|
|
|
2015-03-10 00:12:41 +00:00
|
|
|
NT_ASSERT(ghMouseDevice == NULL);
|
|
|
|
NT_ASSERT(ghKeyboardDevice == NULL);
|
|
|
|
|
2015-10-16 15:30:35 +00:00
|
|
|
PoRequestShutdownEvent(&ShutdownEvent);
|
2014-12-26 12:06:43 +00:00
|
|
|
for (;;)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
2011-10-16 11:39:47 +00:00
|
|
|
if (!ghMouseDevice)
|
|
|
|
{
|
|
|
|
/* Check if mouse device already exists */
|
|
|
|
Status = OpenInputDevice(&ghMouseDevice, &pMouDevice, L"\\Device\\PointerClass0" );
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
++cMaxWaitObjects;
|
|
|
|
TRACE("Mouse connected!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ghKeyboardDevice)
|
|
|
|
{
|
|
|
|
/* Check if keyboard device already exists */
|
|
|
|
Status = OpenInputDevice(&ghKeyboardDevice, &pKbdDevice, L"\\Device\\KeyboardClass0");
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
++cMaxWaitObjects;
|
|
|
|
TRACE("Keyboard connected!\n");
|
2013-10-14 06:19:48 +00:00
|
|
|
// Get and load keyboard attributes.
|
|
|
|
UserInitKeyboard(ghKeyboardDevice);
|
|
|
|
UserEnterExclusive();
|
|
|
|
// Register the Window hotkey.
|
|
|
|
UserRegisterHotKey(PWND_BOTTOM, IDHK_WINKEY, MOD_WIN, 0);
|
2019-01-15 13:36:41 +00:00
|
|
|
// Register the Window Snap hotkey.
|
|
|
|
UserRegisterHotKey(PWND_BOTTOM, IDHK_SNAP_LEFT, MOD_WIN, VK_LEFT);
|
|
|
|
UserRegisterHotKey(PWND_BOTTOM, IDHK_SNAP_RIGHT, MOD_WIN, VK_RIGHT);
|
|
|
|
UserRegisterHotKey(PWND_BOTTOM, IDHK_SNAP_UP, MOD_WIN, VK_UP);
|
|
|
|
UserRegisterHotKey(PWND_BOTTOM, IDHK_SNAP_DOWN, MOD_WIN, VK_DOWN);
|
2013-10-14 06:19:48 +00:00
|
|
|
// Register the debug hotkeys.
|
|
|
|
StartDebugHotKeys();
|
|
|
|
UserLeave();
|
2011-10-16 11:39:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset WaitHandles array */
|
|
|
|
cWaitObjects = 0;
|
2015-10-16 15:30:35 +00:00
|
|
|
WaitObjects[cWaitObjects++] = ShutdownEvent;
|
2011-10-16 11:39:47 +00:00
|
|
|
WaitObjects[cWaitObjects++] = MasterTimer;
|
2011-09-09 16:17:02 +00:00
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
if (ghMouseDevice)
|
|
|
|
{
|
|
|
|
/* Try to read from mouse if previous reading is not pending */
|
|
|
|
if (MouStatus != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
MouStatus = ZwReadFile(ghMouseDevice,
|
2011-09-09 16:17:02 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2011-10-16 11:39:47 +00:00
|
|
|
&MouIosb,
|
|
|
|
&MouseInput,
|
|
|
|
sizeof(MOUSE_INPUT_DATA),
|
|
|
|
&ByteOffset,
|
|
|
|
NULL);
|
|
|
|
}
|
2012-03-04 11:32:43 +00:00
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
if (MouStatus == STATUS_PENDING)
|
|
|
|
WaitObjects[cWaitObjects++] = &pMouDevice->Event;
|
2011-09-09 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
if (ghKeyboardDevice)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
2011-10-16 11:39:47 +00:00
|
|
|
/* Try to read from keyboard if previous reading is not pending */
|
|
|
|
if (KbdStatus != STATUS_PENDING)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
2011-10-16 11:39:47 +00:00
|
|
|
KbdStatus = ZwReadFile(ghKeyboardDevice,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&KbdIosb,
|
|
|
|
&KeyInput,
|
|
|
|
sizeof(KEYBOARD_INPUT_DATA),
|
|
|
|
&ByteOffset,
|
|
|
|
NULL);
|
2012-03-04 11:32:43 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
}
|
2011-10-16 11:39:47 +00:00
|
|
|
if (KbdStatus == STATUS_PENDING)
|
|
|
|
WaitObjects[cWaitObjects++] = &pKbdDevice->Event;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If all objects are pending, wait for them */
|
|
|
|
if (cWaitObjects == cMaxWaitObjects)
|
|
|
|
{
|
|
|
|
Status = KeWaitForMultipleObjects(cWaitObjects,
|
|
|
|
WaitObjects,
|
|
|
|
WaitAny,
|
|
|
|
UserRequest,
|
|
|
|
KernelMode,
|
|
|
|
TRUE,
|
|
|
|
NULL,//&WaitTimeout,
|
2015-10-16 15:30:35 +00:00
|
|
|
WaitBlockArray);
|
2011-10-16 11:39:47 +00:00
|
|
|
|
2012-03-04 11:32:43 +00:00
|
|
|
if ((Status >= STATUS_WAIT_0) &&
|
|
|
|
(Status < (STATUS_WAIT_0 + (LONG)cWaitObjects)))
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
2011-10-16 11:39:47 +00:00
|
|
|
/* Some device has finished reading */
|
|
|
|
pSignaledObject = WaitObjects[Status - STATUS_WAIT_0];
|
|
|
|
|
|
|
|
/* Check if it is mouse or keyboard and update status */
|
2015-03-10 00:12:41 +00:00
|
|
|
if ((MouStatus == STATUS_PENDING) &&
|
|
|
|
(pSignaledObject == &pMouDevice->Event))
|
|
|
|
{
|
2011-10-16 11:39:47 +00:00
|
|
|
MouStatus = MouIosb.Status;
|
2015-03-10 00:12:41 +00:00
|
|
|
}
|
|
|
|
else if ((KbdStatus == STATUS_PENDING) &&
|
|
|
|
(pSignaledObject == &pKbdDevice->Event))
|
|
|
|
{
|
2011-10-16 11:39:47 +00:00
|
|
|
KbdStatus = KbdIosb.Status;
|
2015-03-10 00:12:41 +00:00
|
|
|
}
|
2011-10-16 11:39:47 +00:00
|
|
|
else if (pSignaledObject == MasterTimer)
|
|
|
|
{
|
|
|
|
ProcessTimers();
|
|
|
|
}
|
2015-10-16 15:30:35 +00:00
|
|
|
else if (pSignaledObject == ShutdownEvent)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2011-10-16 11:39:47 +00:00
|
|
|
else ASSERT(FALSE);
|
2011-09-09 16:17:02 +00:00
|
|
|
}
|
2011-10-16 11:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Have we successed reading from mouse? */
|
|
|
|
if (NT_SUCCESS(MouStatus) && MouStatus != STATUS_PENDING)
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
TRACE("MouseEvent\n");
|
2011-10-16 11:39:47 +00:00
|
|
|
|
|
|
|
/* Set LastInputTick */
|
2011-09-09 16:17:02 +00:00
|
|
|
IntLastInputTick(TRUE);
|
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
/* Process data */
|
2011-09-09 16:17:02 +00:00
|
|
|
UserEnterExclusive();
|
2011-10-21 21:23:51 +00:00
|
|
|
UserProcessMouseInput(&MouseInput);
|
2011-09-09 16:17:02 +00:00
|
|
|
UserLeave();
|
|
|
|
}
|
2011-10-16 11:39:47 +00:00
|
|
|
else if (MouStatus != STATUS_PENDING)
|
|
|
|
ERR("Failed to read from mouse: %x.\n", MouStatus);
|
2011-09-09 16:17:02 +00:00
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
/* Have we successed reading from keyboard? */
|
|
|
|
if (NT_SUCCESS(KbdStatus) && KbdStatus != STATUS_PENDING)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
2011-10-16 11:39:47 +00:00
|
|
|
TRACE("KeyboardEvent: %s %04x\n",
|
2011-09-09 16:17:02 +00:00
|
|
|
(KeyInput.Flags & KEY_BREAK) ? "up" : "down",
|
2011-10-16 11:39:47 +00:00
|
|
|
KeyInput.MakeCode);
|
2011-09-09 16:17:02 +00:00
|
|
|
|
|
|
|
/* Set LastInputTick */
|
|
|
|
IntLastInputTick(TRUE);
|
|
|
|
|
2011-10-05 14:09:51 +00:00
|
|
|
/* Process data */
|
2011-09-09 16:17:02 +00:00
|
|
|
UserEnterExclusive();
|
2011-10-05 14:09:51 +00:00
|
|
|
UserProcessKeyboardInput(&KeyInput);
|
2011-09-09 16:17:02 +00:00
|
|
|
UserLeave();
|
|
|
|
}
|
2011-10-16 11:39:47 +00:00
|
|
|
else if (KbdStatus != STATUS_PENDING)
|
|
|
|
ERR("Failed to read from keyboard: %x.\n", KbdStatus);
|
2011-09-09 16:17:02 +00:00
|
|
|
}
|
2015-10-16 15:30:35 +00:00
|
|
|
|
|
|
|
if (ghMouseDevice)
|
|
|
|
{
|
|
|
|
(void)ZwCancelIoFile(ghMouseDevice, &MouIosb);
|
|
|
|
ObCloseHandle(ghMouseDevice, KernelMode);
|
|
|
|
ObDereferenceObject(pMouDevice);
|
|
|
|
ghMouseDevice = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ghKeyboardDevice)
|
|
|
|
{
|
|
|
|
(void)ZwCancelIoFile(ghKeyboardDevice, &KbdIosb);
|
|
|
|
ObCloseHandle(ghKeyboardDevice, KernelMode);
|
|
|
|
ObDereferenceObject(pKbdDevice);
|
|
|
|
ghKeyboardDevice = NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
ERR("Raw Input Thread Exit!\n");
|
2002-01-14 01:11:58 +00:00
|
|
|
}
|
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
/*
|
|
|
|
* InitInputImpl
|
|
|
|
*
|
|
|
|
* Inits input implementation
|
|
|
|
*/
|
2020-10-06 19:44:01 +00:00
|
|
|
CODE_SEG("INIT")
|
2010-11-03 00:51:19 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2002-01-14 01:11:58 +00:00
|
|
|
InitInputImpl(VOID)
|
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
MasterTimer = ExAllocatePoolWithTag(NonPagedPool, sizeof(KTIMER), USERTAG_SYSTEM);
|
|
|
|
if (!MasterTimer)
|
|
|
|
{
|
2011-10-16 11:39:47 +00:00
|
|
|
ERR("Failed to allocate memory\n");
|
2011-09-09 16:17:02 +00:00
|
|
|
ASSERT(FALSE);
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
KeInitializeTimer(MasterTimer);
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2002-01-14 01:11:58 +00:00
|
|
|
}
|
|
|
|
|
2004-04-29 20:26:35 +00:00
|
|
|
BOOL FASTCALL
|
2011-10-05 14:09:51 +00:00
|
|
|
IntBlockInput(PTHREADINFO pti, BOOL BlockIt)
|
2004-04-29 20:26:35 +00:00
|
|
|
{
|
2011-09-09 16:17:02 +00:00
|
|
|
PTHREADINFO OldBlock;
|
2011-10-05 14:09:51 +00:00
|
|
|
ASSERT(pti);
|
2011-09-09 16:17:02 +00:00
|
|
|
|
2011-10-05 14:09:51 +00:00
|
|
|
if(!pti->rpdesk || ((pti->TIF_flags & TIF_INCLEANUP) && BlockIt))
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
|
|
|
/*
|
2011-12-14 04:07:06 +00:00
|
|
|
* Fail blocking if exiting the thread
|
2011-09-09 16:17:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-12-14 04:07:06 +00:00
|
|
|
* FIXME: Check access rights of the window station
|
|
|
|
* e.g. services running in the service window station cannot block input
|
2011-09-09 16:17:02 +00:00
|
|
|
*/
|
2011-10-05 14:09:51 +00:00
|
|
|
if(!ThreadHasInputAccess(pti) ||
|
2011-10-13 22:22:49 +00:00
|
|
|
!IntIsActiveDesktop(pti->rpdesk))
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
|
|
|
EngSetLastError(ERROR_ACCESS_DENIED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-10-05 14:09:51 +00:00
|
|
|
ASSERT(pti->rpdesk);
|
|
|
|
OldBlock = pti->rpdesk->BlockInputThread;
|
2011-09-09 16:17:02 +00:00
|
|
|
if(OldBlock)
|
|
|
|
{
|
2011-10-05 14:09:51 +00:00
|
|
|
if(OldBlock != pti)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
|
|
|
EngSetLastError(ERROR_ACCESS_DENIED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-10-05 14:09:51 +00:00
|
|
|
pti->rpdesk->BlockInputThread = (BlockIt ? pti : NULL);
|
2011-09-09 16:17:02 +00:00
|
|
|
return OldBlock == NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-05 14:09:51 +00:00
|
|
|
pti->rpdesk->BlockInputThread = (BlockIt ? pti : NULL);
|
2011-09-09 16:17:02 +00:00
|
|
|
return OldBlock == NULL;
|
2004-04-29 20:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2004-04-29 20:26:35 +00:00
|
|
|
NtUserBlockInput(
|
2011-09-09 16:17:02 +00:00
|
|
|
BOOL BlockIt)
|
2004-04-29 20:26:35 +00:00
|
|
|
{
|
2011-10-11 19:22:07 +00:00
|
|
|
BOOL ret;
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
TRACE("Enter NtUserBlockInput\n");
|
|
|
|
UserEnterExclusive();
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-10-11 19:22:07 +00:00
|
|
|
ret = IntBlockInput(PsGetCurrentThreadWin32Thread(), BlockIt);
|
2005-09-05 21:19:23 +00:00
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
UserLeave();
|
2011-10-11 19:22:07 +00:00
|
|
|
TRACE("Leave NtUserBlockInput, ret=%i\n", ret);
|
|
|
|
|
|
|
|
return ret;
|
2004-04-29 20:26:35 +00:00
|
|
|
}
|
|
|
|
|
2013-10-20 05:16:52 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
|
|
|
IsRemoveAttachThread(PTHREADINFO pti)
|
2012-08-06 03:13:27 +00:00
|
|
|
{
|
2013-10-20 05:16:52 +00:00
|
|
|
NTSTATUS Status;
|
2012-08-06 03:13:27 +00:00
|
|
|
PATTACHINFO pai;
|
2013-10-20 05:16:52 +00:00
|
|
|
BOOL Ret = TRUE;
|
|
|
|
PTHREADINFO ptiFrom = NULL, ptiTo = NULL;
|
2012-08-06 03:13:27 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2013-10-20 05:16:52 +00:00
|
|
|
if (!gpai) return TRUE;
|
2015-03-10 00:12:41 +00:00
|
|
|
|
2013-10-20 05:16:52 +00:00
|
|
|
pai = gpai; // Bottom of the list.
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (pai->pti2 == pti)
|
|
|
|
{
|
|
|
|
ptiFrom = pai->pti1;
|
|
|
|
ptiTo = pti;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pai->pti1 == pti)
|
|
|
|
{
|
|
|
|
ptiFrom = pti;
|
|
|
|
ptiTo = pai->pti2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pai = pai->paiNext;
|
2015-03-10 00:12:41 +00:00
|
|
|
|
2013-10-20 05:16:52 +00:00
|
|
|
} while (pai);
|
|
|
|
|
|
|
|
if (!pai && !ptiFrom && !ptiTo) break;
|
|
|
|
|
|
|
|
Status = UserAttachThreadInput(ptiFrom, ptiTo, FALSE);
|
|
|
|
if (!NT_SUCCESS(Status)) Ret = FALSE;
|
|
|
|
|
|
|
|
} while (Ret);
|
|
|
|
|
|
|
|
return Ret;
|
2012-08-06 03:13:27 +00:00
|
|
|
}
|
|
|
|
|
2022-04-16 21:53:37 +00:00
|
|
|
// Win: zzzAttachThreadInput
|
2012-08-18 22:13:38 +00:00
|
|
|
NTSTATUS FASTCALL
|
2012-06-07 01:08:41 +00:00
|
|
|
UserAttachThreadInput(PTHREADINFO ptiFrom, PTHREADINFO ptiTo, BOOL fAttach)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
2012-06-08 21:19:31 +00:00
|
|
|
MSG msg;
|
2011-09-09 16:17:02 +00:00
|
|
|
PATTACHINFO pai;
|
2015-02-05 00:11:35 +00:00
|
|
|
PCURICON_OBJECT CurIcon;
|
2011-09-09 16:17:02 +00:00
|
|
|
|
2011-12-14 04:07:06 +00:00
|
|
|
/* Can not be the same thread. */
|
2012-08-18 22:13:38 +00:00
|
|
|
if (ptiFrom == ptiTo) return STATUS_INVALID_PARAMETER;
|
2011-09-09 16:17:02 +00:00
|
|
|
|
|
|
|
/* Do not attach to system threads or between different desktops. */
|
2012-06-07 01:08:41 +00:00
|
|
|
if (ptiFrom->TIF_flags & TIF_DONTATTACHQUEUE ||
|
2012-08-18 22:13:38 +00:00
|
|
|
ptiTo->TIF_flags & TIF_DONTATTACHQUEUE ||
|
|
|
|
ptiFrom->rpdesk != ptiTo->rpdesk)
|
|
|
|
return STATUS_ACCESS_DENIED;
|
2011-09-09 16:17:02 +00:00
|
|
|
|
2012-08-06 05:04:15 +00:00
|
|
|
/* MSDN Note:
|
2012-08-06 06:20:06 +00:00
|
|
|
Keyboard and mouse events received by both threads are processed by the thread specified by the idAttachTo.
|
2012-08-06 05:04:15 +00:00
|
|
|
*/
|
|
|
|
|
2011-09-09 16:17:02 +00:00
|
|
|
/* If Attach set, allocate and link. */
|
2011-10-14 19:01:35 +00:00
|
|
|
if (fAttach)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
|
|
|
pai = ExAllocatePoolWithTag(PagedPool, sizeof(ATTACHINFO), USERTAG_ATTACHINFO);
|
2012-08-18 22:13:38 +00:00
|
|
|
if (!pai) return STATUS_NO_MEMORY;
|
2011-09-09 16:17:02 +00:00
|
|
|
|
|
|
|
pai->paiNext = gpai;
|
2012-06-07 01:08:41 +00:00
|
|
|
pai->pti1 = ptiFrom;
|
2011-09-09 16:17:02 +00:00
|
|
|
pai->pti2 = ptiTo;
|
|
|
|
gpai = pai;
|
2012-08-18 22:13:38 +00:00
|
|
|
paiCount++;
|
|
|
|
ERR("Attach Allocated! ptiFrom 0x%p ptiTo 0x%p paiCount %d\n",ptiFrom,ptiTo,paiCount);
|
|
|
|
|
2013-10-20 05:16:52 +00:00
|
|
|
if (ptiTo->MessageQueue != ptiFrom->MessageQueue)
|
2012-08-18 22:13:38 +00:00
|
|
|
{
|
2012-06-07 01:08:41 +00:00
|
|
|
|
2013-10-20 05:16:52 +00:00
|
|
|
ptiTo->MessageQueue->iCursorLevel -= ptiFrom->iCursorLevel;
|
2012-08-18 22:13:38 +00:00
|
|
|
|
2013-10-20 05:16:52 +00:00
|
|
|
if (ptiFrom->MessageQueue == gpqForeground)
|
|
|
|
{
|
|
|
|
ERR("ptiFrom is Foreground\n");
|
|
|
|
ptiTo->MessageQueue->spwndActive = ptiFrom->MessageQueue->spwndActive;
|
|
|
|
ptiTo->MessageQueue->spwndFocus = ptiFrom->MessageQueue->spwndFocus;
|
|
|
|
ptiTo->MessageQueue->spwndCapture = ptiFrom->MessageQueue->spwndCapture;
|
|
|
|
ptiTo->MessageQueue->QF_flags ^= ((ptiTo->MessageQueue->QF_flags ^ ptiFrom->MessageQueue->QF_flags) & QF_CAPTURELOCKED);
|
2015-10-24 15:46:34 +00:00
|
|
|
RtlCopyMemory(&ptiTo->MessageQueue->CaretInfo,
|
|
|
|
&ptiFrom->MessageQueue->CaretInfo,
|
|
|
|
sizeof(ptiTo->MessageQueue->CaretInfo));
|
2013-10-20 05:16:52 +00:00
|
|
|
IntSetFocusMessageQueue(NULL);
|
|
|
|
IntSetFocusMessageQueue(ptiTo->MessageQueue);
|
|
|
|
gptiForeground = ptiTo;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("ptiFrom NOT Foreground\n");
|
2015-09-01 01:48:37 +00:00
|
|
|
if ( ptiTo->MessageQueue->spwndActive == 0 )
|
|
|
|
ptiTo->MessageQueue->spwndActive = ptiFrom->MessageQueue->spwndActive;
|
|
|
|
if ( ptiTo->MessageQueue->spwndFocus == 0 )
|
|
|
|
ptiTo->MessageQueue->spwndFocus = ptiFrom->MessageQueue->spwndFocus;
|
2013-10-20 05:16:52 +00:00
|
|
|
}
|
2012-08-18 22:13:38 +00:00
|
|
|
|
2015-02-05 00:11:35 +00:00
|
|
|
CurIcon = ptiFrom->MessageQueue->CursorObject;
|
|
|
|
|
2013-10-20 05:16:52 +00:00
|
|
|
MsqDestroyMessageQueue(ptiFrom);
|
|
|
|
|
2015-03-29 16:25:50 +00:00
|
|
|
if (CurIcon)
|
|
|
|
{
|
|
|
|
// Could be global. Keep it above the water line!
|
|
|
|
UserReferenceObject(CurIcon);
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:11:35 +00:00
|
|
|
if (CurIcon && UserObjectInDestroy(UserHMGetHandle(CurIcon)))
|
|
|
|
{
|
2015-03-29 16:25:50 +00:00
|
|
|
UserDereferenceObject(CurIcon);
|
2015-02-05 00:11:35 +00:00
|
|
|
CurIcon = NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-20 05:16:52 +00:00
|
|
|
ptiFrom->MessageQueue = ptiTo->MessageQueue;
|
|
|
|
|
2015-02-05 00:11:35 +00:00
|
|
|
// Pass cursor From if To is null. Pass test_SetCursor parent_id == current pti ID.
|
|
|
|
if (CurIcon && ptiTo->MessageQueue->CursorObject == NULL)
|
|
|
|
{
|
2015-03-29 16:25:50 +00:00
|
|
|
ERR("ptiTo receiving ptiFrom Cursor\n");
|
2015-02-05 00:11:35 +00:00
|
|
|
ptiTo->MessageQueue->CursorObject = CurIcon;
|
|
|
|
}
|
|
|
|
|
2013-10-20 05:16:52 +00:00
|
|
|
ptiFrom->MessageQueue->cThreads++;
|
2015-03-10 00:12:41 +00:00
|
|
|
ERR("ptiTo S Share count %u\n", ptiFrom->MessageQueue->cThreads);
|
2013-10-20 05:16:52 +00:00
|
|
|
|
|
|
|
IntReferenceMessageQueue(ptiTo->MessageQueue);
|
2012-08-18 22:13:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-20 05:16:52 +00:00
|
|
|
ERR("Attach Threads are already associated!\n");
|
2012-08-18 22:13:38 +00:00
|
|
|
}
|
2011-09-09 16:17:02 +00:00
|
|
|
}
|
|
|
|
else /* If clear, unlink and free it. */
|
|
|
|
{
|
2012-08-18 22:13:38 +00:00
|
|
|
BOOL Hit = FALSE;
|
|
|
|
PATTACHINFO *ppai;
|
2011-09-09 16:17:02 +00:00
|
|
|
|
2012-08-18 22:13:38 +00:00
|
|
|
if (!gpai) return STATUS_INVALID_PARAMETER;
|
2011-09-09 16:17:02 +00:00
|
|
|
|
|
|
|
/* Search list and free if found or return false. */
|
2012-08-18 22:13:38 +00:00
|
|
|
ppai = &gpai;
|
|
|
|
while (*ppai != NULL)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
2012-08-18 22:13:38 +00:00
|
|
|
if ( (*ppai)->pti2 == ptiTo && (*ppai)->pti1 == ptiFrom )
|
|
|
|
{
|
|
|
|
pai = *ppai;
|
|
|
|
/* Remove it from the list */
|
|
|
|
*ppai = (*ppai)->paiNext;
|
|
|
|
ExFreePoolWithTag(pai, USERTAG_ATTACHINFO);
|
|
|
|
paiCount--;
|
|
|
|
Hit = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ppai = &((*ppai)->paiNext);
|
|
|
|
}
|
2011-09-09 16:17:02 +00:00
|
|
|
|
2012-08-18 22:13:38 +00:00
|
|
|
if (!Hit) return STATUS_INVALID_PARAMETER;
|
2015-03-10 00:12:41 +00:00
|
|
|
|
2012-08-18 22:13:38 +00:00
|
|
|
ERR("Attach Free! ptiFrom 0x%p ptiTo 0x%p paiCount %d\n",ptiFrom,ptiTo,paiCount);
|
2015-03-10 00:12:41 +00:00
|
|
|
|
2013-10-20 05:16:52 +00:00
|
|
|
if (ptiTo->MessageQueue == ptiFrom->MessageQueue)
|
|
|
|
{
|
2015-09-01 01:48:37 +00:00
|
|
|
PWND spwndActive = ptiTo->MessageQueue->spwndActive;
|
|
|
|
PWND spwndFocus = ptiTo->MessageQueue->spwndFocus;
|
|
|
|
|
2013-10-20 05:16:52 +00:00
|
|
|
if (gptiForeground == ptiFrom)
|
|
|
|
{
|
|
|
|
ERR("ptiTo is now pti FG.\n");
|
|
|
|
// MessageQueue foreground is set so switch threads.
|
|
|
|
gptiForeground = ptiTo;
|
|
|
|
}
|
|
|
|
ptiTo->MessageQueue->cThreads--;
|
2015-03-10 00:12:41 +00:00
|
|
|
ERR("ptiTo E Share count %u\n", ptiTo->MessageQueue->cThreads);
|
2013-10-20 05:16:52 +00:00
|
|
|
ASSERT(ptiTo->MessageQueue->cThreads >= 1);
|
|
|
|
|
|
|
|
IntDereferenceMessageQueue(ptiTo->MessageQueue);
|
|
|
|
|
|
|
|
ptiFrom->MessageQueue = MsqCreateMessageQueue(ptiFrom);
|
2011-09-09 16:17:02 +00:00
|
|
|
|
2015-09-01 01:48:37 +00:00
|
|
|
if (spwndActive)
|
|
|
|
{
|
|
|
|
if (spwndActive->head.pti == ptiFrom)
|
|
|
|
{
|
|
|
|
ptiFrom->MessageQueue->spwndActive = spwndActive;
|
|
|
|
ptiTo->MessageQueue->spwndActive = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (spwndFocus)
|
|
|
|
{
|
|
|
|
if (spwndFocus->head.pti == ptiFrom)
|
|
|
|
{
|
|
|
|
ptiFrom->MessageQueue->spwndFocus = spwndFocus;
|
|
|
|
ptiTo->MessageQueue->spwndFocus = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-10-20 05:16:52 +00:00
|
|
|
ptiTo->MessageQueue->iCursorLevel -= ptiFrom->iCursorLevel;
|
|
|
|
}
|
|
|
|
else
|
2012-08-18 22:13:38 +00:00
|
|
|
{
|
2013-10-20 05:16:52 +00:00
|
|
|
ERR("Detaching Threads are not associated!\n");
|
2012-08-18 22:13:38 +00:00
|
|
|
}
|
2012-06-07 01:08:41 +00:00
|
|
|
}
|
|
|
|
/* Note that key state, which can be ascertained by calls to the GetKeyState
|
|
|
|
or GetKeyboardState function, is reset after a call to AttachThreadInput.
|
|
|
|
ATM which one?
|
|
|
|
*/
|
|
|
|
RtlCopyMemory(ptiTo->MessageQueue->afKeyState, gafAsyncKeyState, sizeof(gafAsyncKeyState));
|
2012-06-08 21:19:31 +00:00
|
|
|
|
2015-09-01 01:48:37 +00:00
|
|
|
ptiTo->MessageQueue->msgDblClk.message = 0;
|
|
|
|
|
2012-06-08 21:19:31 +00:00
|
|
|
/* Generate mouse move message */
|
|
|
|
msg.message = WM_MOUSEMOVE;
|
|
|
|
msg.wParam = UserGetMouseButtonsState();
|
|
|
|
msg.lParam = MAKELPARAM(gpsi->ptCursor.x, gpsi->ptCursor.y);
|
|
|
|
msg.pt = gpsi->ptCursor;
|
|
|
|
co_MsqInsertMouseMessage(&msg, 0, 0, TRUE);
|
|
|
|
|
2012-08-18 22:13:38 +00:00
|
|
|
return STATUS_SUCCESS;
|
2009-10-10 04:40:36 +00:00
|
|
|
}
|
|
|
|
|
2013-11-22 18:45:58 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
NtUserAttachThreadInput(
|
|
|
|
IN DWORD idAttach,
|
|
|
|
IN DWORD idAttachTo,
|
|
|
|
IN BOOL fAttach)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PTHREADINFO pti, ptiTo;
|
|
|
|
BOOL Ret = FALSE;
|
|
|
|
|
|
|
|
UserEnterExclusive();
|
2015-02-05 00:11:35 +00:00
|
|
|
TRACE("Enter NtUserAttachThreadInput %s\n",(fAttach ? "TRUE" : "FALSE" ));
|
2013-11-22 18:45:58 +00:00
|
|
|
|
2018-03-18 14:53:52 +00:00
|
|
|
pti = IntTID2PTI(UlongToHandle(idAttach));
|
|
|
|
ptiTo = IntTID2PTI(UlongToHandle(idAttachTo));
|
2013-11-22 18:45:58 +00:00
|
|
|
|
|
|
|
if ( !pti || !ptiTo )
|
|
|
|
{
|
2015-02-05 00:11:35 +00:00
|
|
|
TRACE("AttachThreadInput pti or ptiTo NULL.\n");
|
2013-11-22 18:45:58 +00:00
|
|
|
EngSetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = UserAttachThreadInput( pti, ptiTo, fAttach);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2015-02-05 00:11:35 +00:00
|
|
|
TRACE("AttachThreadInput Error Status 0x%x. \n",Status);
|
2013-11-22 18:45:58 +00:00
|
|
|
EngSetLastError(RtlNtStatusToDosError(Status));
|
|
|
|
}
|
|
|
|
else Ret = TRUE;
|
|
|
|
|
|
|
|
Exit:
|
2015-02-05 00:11:35 +00:00
|
|
|
TRACE("Leave NtUserAttachThreadInput, ret=%d\n",Ret);
|
2013-11-22 18:45:58 +00:00
|
|
|
UserLeave();
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2011-10-16 11:39:47 +00:00
|
|
|
/*
|
|
|
|
* NtUserSendInput
|
|
|
|
*
|
|
|
|
* Generates input events from software
|
|
|
|
*/
|
2004-04-29 20:26:35 +00:00
|
|
|
UINT
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2004-04-29 20:26:35 +00:00
|
|
|
NtUserSendInput(
|
2011-09-09 16:17:02 +00:00
|
|
|
UINT nInputs,
|
|
|
|
LPINPUT pInput,
|
|
|
|
INT cbSize)
|
2004-04-29 20:26:35 +00:00
|
|
|
{
|
2011-10-05 14:09:51 +00:00
|
|
|
PTHREADINFO pti;
|
2011-10-14 19:01:35 +00:00
|
|
|
UINT uRet = 0;
|
2011-09-09 16:17:02 +00:00
|
|
|
|
|
|
|
TRACE("Enter NtUserSendInput\n");
|
|
|
|
UserEnterExclusive();
|
|
|
|
|
2011-10-05 14:09:51 +00:00
|
|
|
pti = PsGetCurrentThreadWin32Thread();
|
|
|
|
ASSERT(pti);
|
2011-09-09 16:17:02 +00:00
|
|
|
|
2011-10-05 14:09:51 +00:00
|
|
|
if (!pti->rpdesk)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
2011-10-14 19:01:35 +00:00
|
|
|
goto cleanup;
|
2011-09-09 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 14:09:51 +00:00
|
|
|
if (!nInputs || !pInput || cbSize != sizeof(INPUT))
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
|
|
|
EngSetLastError(ERROR_INVALID_PARAMETER);
|
2011-10-14 19:01:35 +00:00
|
|
|
goto cleanup;
|
2011-09-09 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-12-14 04:07:06 +00:00
|
|
|
* FIXME: Check access rights of the window station
|
|
|
|
* e.g. services running in the service window station cannot block input
|
2011-09-09 16:17:02 +00:00
|
|
|
*/
|
2011-10-05 14:09:51 +00:00
|
|
|
if (!ThreadHasInputAccess(pti) ||
|
2011-10-14 18:41:06 +00:00
|
|
|
!IntIsActiveDesktop(pti->rpdesk))
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
|
|
|
EngSetLastError(ERROR_ACCESS_DENIED);
|
2011-10-14 19:01:35 +00:00
|
|
|
goto cleanup;
|
2011-09-09 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 14:09:51 +00:00
|
|
|
while (nInputs--)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
|
|
|
INPUT SafeInput;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
Status = MmCopyFromCaller(&SafeInput, pInput++, sizeof(INPUT));
|
2011-10-05 14:09:51 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
|
|
|
SetLastNtError(Status);
|
2011-10-14 19:01:35 +00:00
|
|
|
goto cleanup;
|
2011-09-09 16:17:02 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 14:09:51 +00:00
|
|
|
switch (SafeInput.type)
|
2011-09-09 16:17:02 +00:00
|
|
|
{
|
|
|
|
case INPUT_MOUSE:
|
2011-10-21 21:23:51 +00:00
|
|
|
if (UserSendMouseInput(&SafeInput.mi, TRUE))
|
2011-10-14 19:01:35 +00:00
|
|
|
uRet++;
|
2011-09-09 16:17:02 +00:00
|
|
|
break;
|
|
|
|
case INPUT_KEYBOARD:
|
2011-10-05 14:09:51 +00:00
|
|
|
if (UserSendKeyboardInput(&SafeInput.ki, TRUE))
|
2011-10-14 19:01:35 +00:00
|
|
|
uRet++;
|
2011-09-09 16:17:02 +00:00
|
|
|
break;
|
|
|
|
case INPUT_HARDWARE:
|
2022-05-02 12:26:10 +00:00
|
|
|
FIXME("INPUT_HARDWARE not supported!\n");
|
2011-09-09 16:17:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("SendInput(): Invalid input type: 0x%x\n", SafeInput.type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-10-14 19:01:35 +00:00
|
|
|
cleanup:
|
2013-09-01 23:58:37 +00:00
|
|
|
TRACE("Leave NtUserSendInput, ret=%u\n", uRet);
|
2011-09-09 16:17:02 +00:00
|
|
|
UserLeave();
|
2011-10-14 19:01:35 +00:00
|
|
|
return uRet;
|
2004-04-29 20:26:35 +00:00
|
|
|
}
|
|
|
|
|
2002-01-14 01:11:58 +00:00
|
|
|
/* EOF */
|