Skip to content

Commit 26b0b18

Browse files
committed
raw inputt
1 parent fda644a commit 26b0b18

11 files changed

Lines changed: 442 additions & 189 deletions

File tree

win32ss/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ list(APPEND SOURCE
147147
user/ntuser/painting.c
148148
user/ntuser/power.c
149149
user/ntuser/prop.c
150+
user/ntuser/rawinput.c
150151
user/ntuser/scrollbar.c
151152
user/ntuser/scrollex.c
152153
user/ntuser/security.c

win32ss/user/ntuser/input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ INT paiCount = 0;
2626
HANDLE ghKeyboardDevice = NULL;
2727

2828
static DWORD LastInputTick = 0;
29-
static HANDLE ghMouseDevice;
29+
HANDLE ghMouseDevice;
3030

3131
/* FUNCTIONS *****************************************************************/
3232

win32ss/user/ntuser/keyboard.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static enum _ALTNUM_STATE
3434

3535
static ULONG gAltNumPadValue = 0;
3636
BOOL gbEnableHexNumpad = FALSE;
37+
extern BOOLEAN RawInputEnabled;
38+
extern HANDLE ghKeyboardDevice;
3739

3840
/* FUNCTIONS *****************************************************************/
3941

@@ -1405,6 +1407,69 @@ UserSendKeyboardInput(KEYBDINPUT *pKbdInput, BOOL bInjected)
14051407
return ProcessKeyEvent(wVk, wScanCode, pKbdInput->dwFlags, bInjected, dwTime, pKbdInput->dwExtraInfo);
14061408
}
14071409

1410+
VOID
1411+
WINAPI
1412+
UserRawInputProcessKeyboardInput(
1413+
PKEYBOARD_INPUT_DATA pKbdInputData,
1414+
WORD wScanCode, WORD wVk)
1415+
{
1416+
PUSER_MESSAGE_QUEUE pFocusQueue;
1417+
PTHREADINFO pti;
1418+
POINT ptCursor;
1419+
1420+
RAWKEYBOARD kb = {0};
1421+
1422+
/* Find the target thread whose locale is in effect */
1423+
pFocusQueue = IntGetFocusMessageQueue();
1424+
if ( pFocusQueue)
1425+
{
1426+
ptCursor = gpsi->ptCursor;
1427+
MSG Msg;
1428+
PWND pWnd = pFocusQueue->spwndFocus;
1429+
if (pWnd)
1430+
{
1431+
pti = pWnd->head.pti;
1432+
BOOL bIsDown = (pKbdInputData->Flags & KEY_BREAK) ? FALSE : TRUE;
1433+
1434+
kb.MakeCode = wScanCode & 0x7F;
1435+
1436+
if (bIsDown)
1437+
kb.Flags = RI_KEY_MAKE;
1438+
else
1439+
kb.Flags = RI_KEY_BREAK;
1440+
kb.VKey = wVk & 0xFF; // Note: wVk is simplified by msg queue
1441+
1442+
if (bIsDown)
1443+
kb.Message = WM_KEYDOWN;
1444+
else
1445+
kb.Message = WM_KEYUP;
1446+
if (pKbdInputData->Flags & KEY_E1)
1447+
{
1448+
kb.Flags |= RI_KEY_E1;
1449+
}
1450+
if (pKbdInputData->Flags & KEY_E0)
1451+
{
1452+
kb.Flags |= RI_KEY_E0;
1453+
}
1454+
1455+
kb.ExtraInformation = pKbdInputData->ExtraInformation;
1456+
PRAWINPUT rmInput = EngAllocMem(0, sizeof(RAWINPUT), 'iwar');
1457+
rmInput->header.dwType = RIM_TYPEKEYBOARD;
1458+
rmInput->header.hDevice = ghKeyboardDevice;
1459+
rmInput->header.wParam = pKbdInputData->ExtraInformation;
1460+
rmInput->header.dwSize = sizeof(RAWINPUTHEADER) + sizeof(RAWKEYBOARD);
1461+
rmInput->data.keyboard = kb;
1462+
Msg.wParam = RIM_INPUT;
1463+
Msg.lParam = (LPARAM)(rmInput);
1464+
Msg.pt = ptCursor;
1465+
//Msg.time = mid->time;
1466+
Msg.message = WM_INPUT;
1467+
1468+
//MessageQueue = pti->MessageQueue;
1469+
MsqPostMessage(pti, &Msg, TRUE, QS_RAWINPUT , 0, 0);
1470+
}
1471+
}
1472+
}
14081473
/*
14091474
* UserProcessKeyboardInput
14101475
*
@@ -1448,6 +1513,9 @@ UserProcessKeyboardInput(
14481513
TRACE("UserProcessKeyboardInput: %x (break: %u) -> %x\n",
14491514
wScanCode, (pKbdInputData->Flags & KEY_BREAK) ? 1u : 0, wVk);
14501515

1516+
if (RawInputEnabled == TRUE)
1517+
UserRawInputProcessKeyboardInput(pKbdInputData, wScanCode, wVk);
1518+
14511519
if (wVk)
14521520
{
14531521
KEYBDINPUT KbdInput;

win32ss/user/ntuser/message.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
DBG_DEFAULT_CHANNEL(UserMsg);
1313

14-
#define PM_BADMSGFLAGS ~((QS_RAWINPUT << 16)|PM_QS_SENDMESSAGE|PM_QS_PAINT|PM_QS_POSTMESSAGE|PM_QS_INPUT|PM_NOYIELD|PM_REMOVE)
14+
#define PM_BADMSGFLAGS ~(PM_QS_SENDMESSAGE|PM_QS_PAINT|PM_QS_POSTMESSAGE|PM_QS_INPUT|PM_NOYIELD|PM_REMOVE)
1515

1616
/* Strings that are OK to pass between user and kernel mode.
1717
* There may be other strings needed that can easily be added here. */
@@ -1105,7 +1105,7 @@ co_IntPeekMessage( PMSG Msg,
11051105
}
11061106

11071107
/* Check for hardware events. */
1108-
if ((ProcessMask & QS_INPUT) &&
1108+
if ((ProcessMask & QS_INPUT || ProcessMask & QS_RAWINPUT) &&
11091109
co_MsqPeekHardwareMessage( pti,
11101110
RemoveMessages,
11111111
Window,

win32ss/user/ntuser/misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ NtUserGetThreadState(
309309
break;
310310

311311
case THREADSTATE_GETINPUTSTATE:
312-
ret = LOWORD(IntGetQueueStatus(QS_POSTMESSAGE|QS_TIMER|QS_PAINT|QS_SENDMESSAGE|QS_INPUT)) & (QS_KEY | QS_MOUSEBUTTON);
312+
ret = LOWORD(IntGetQueueStatus(QS_POSTMESSAGE|QS_TIMER|QS_PAINT|QS_SENDMESSAGE|QS_INPUT|QS_RAWINPUT)) & (QS_KEY | QS_MOUSEBUTTON);
313313
break;
314314

315315
case THREADSTATE_FOREGROUNDTHREAD:

win32ss/user/ntuser/mouse.c

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <win32k.h>
1111
DBG_DEFAULT_CHANNEL(UserInput);
1212

13+
extern BOOLEAN RawInputEnabled;
14+
extern HANDLE ghMouseDevice;
15+
1316
MOUSEMOVEPOINT gMouseHistoryOfMoves[64];
1417
INT gcMouseHistoryOfMoves = 0;
1518

@@ -31,6 +34,74 @@ UserGetMouseButtonsState(VOID)
3134
return wRet;
3235
}
3336

37+
VOID NTAPI
38+
UserRawInputMouseProcess(PMOUSE_INPUT_DATA mid)
39+
{
40+
PUSER_MESSAGE_QUEUE pFocusQueue;
41+
PTHREADINFO pti;
42+
POINT ptCursor;
43+
44+
RAWMOUSE rm = {0};
45+
46+
/* Find the target thread whose locale is in effect */
47+
pFocusQueue = IntGetFocusMessageQueue();
48+
if ( pFocusQueue)
49+
{
50+
ptCursor = gpsi->ptCursor;
51+
MSG Msg;
52+
PWND pWnd = pFocusQueue->spwndFocus;
53+
if (pWnd)
54+
{
55+
pti = pWnd->head.pti;
56+
if (mid->LastX != 0 || mid->LastY != 0)
57+
{
58+
rm.usFlags |= MOUSE_MOVE_RELATIVE;
59+
}
60+
61+
/* Flags for absolute move */
62+
if (mid->Flags & MOUSE_MOVE_ABSOLUTE)
63+
rm.usFlags |= MOUSE_MOVE_ABSOLUTE;
64+
if (mid->Flags & MOUSE_VIRTUAL_DESKTOP)
65+
rm.usFlags |= MOUSE_VIRTUAL_DESKTOP;
66+
67+
/* Left button */
68+
if (mid->ButtonFlags & MOUSE_LEFT_BUTTON_DOWN)
69+
rm.usButtonFlags |= RI_MOUSE_LEFT_BUTTON_DOWN;
70+
if (mid->ButtonFlags & MOUSE_LEFT_BUTTON_UP)
71+
rm.usButtonFlags |= RI_MOUSE_LEFT_BUTTON_UP;
72+
73+
/* Middle button */
74+
if (mid->ButtonFlags & MOUSE_MIDDLE_BUTTON_DOWN)
75+
rm.usButtonFlags |= MOUSEEVENTF_MIDDLEDOWN;
76+
if (mid->ButtonFlags & MOUSE_MIDDLE_BUTTON_UP)
77+
rm.usButtonFlags |= MOUSEEVENTF_MIDDLEUP;
78+
79+
/* Right button */
80+
if (mid->ButtonFlags & MOUSE_RIGHT_BUTTON_DOWN)
81+
rm.usButtonFlags |= RI_MOUSE_RIGHT_BUTTON_DOWN;
82+
if (mid->ButtonFlags & MOUSE_RIGHT_BUTTON_UP)
83+
rm.usButtonFlags |= RI_MOUSE_RIGHT_BUTTON_UP;
84+
rm.lLastX = mid->LastX;
85+
rm.lLastY = mid->LastY;
86+
87+
PRAWINPUT rmInput = EngAllocMem(0, sizeof(RAWINPUT), 'iwar');
88+
rmInput->header.dwType = RIM_TYPEMOUSE;
89+
rmInput->header.hDevice = ghMouseDevice;
90+
rmInput->header.wParam = mid->ExtraInformation;
91+
rmInput->header.dwSize = sizeof(RAWINPUTHEADER) + sizeof(RAWMOUSE);
92+
rmInput->data.mouse = rm;
93+
Msg.wParam = RIM_INPUT;
94+
Msg.lParam = (LPARAM)(rmInput);
95+
Msg.pt = ptCursor;
96+
//Msg.time = mid->time;
97+
Msg.message = WM_INPUT;
98+
//MessageQueue = pti->MessageQueue;
99+
100+
MsqPostMessage(pti, &Msg, TRUE, QS_RAWINPUT , 0, 0);
101+
}
102+
}
103+
104+
}
34105
/*
35106
* UserProcessMouseInput
36107
*
@@ -48,7 +119,8 @@ UserProcessMouseInput(PMOUSE_INPUT_DATA mid)
48119
mi.dwFlags = 0;
49120
mi.time = 0;
50121
mi.dwExtraInfo = mid->ExtraInformation;
51-
122+
if (RawInputEnabled== TRUE)
123+
UserRawInputMouseProcess(mid);
52124
/* Mouse position */
53125
if (mi.dx != 0 || mi.dy != 0)
54126
mi.dwFlags |= MOUSEEVENTF_MOVE;

win32ss/user/ntuser/ntstubs.c

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -388,65 +388,6 @@ NtUserYieldTask(VOID)
388388
return 0;
389389
}
390390

391-
DWORD
392-
APIENTRY
393-
NtUserGetRawInputBuffer(
394-
PRAWINPUT pData,
395-
PUINT pcbSize,
396-
UINT cbSizeHeader)
397-
{
398-
STUB;
399-
return 0;
400-
}
401-
402-
DWORD
403-
APIENTRY
404-
NtUserGetRawInputData(
405-
HRAWINPUT hRawInput,
406-
UINT uiCommand,
407-
LPVOID pData,
408-
PUINT pcbSize,
409-
UINT cbSizeHeader)
410-
{
411-
STUB;
412-
return 0;
413-
}
414-
415-
DWORD
416-
APIENTRY
417-
NtUserGetRawInputDeviceInfo(
418-
HANDLE hDevice,
419-
UINT uiCommand,
420-
LPVOID pData,
421-
PUINT pcbSize
422-
)
423-
{
424-
STUB;
425-
return 0;
426-
}
427-
428-
DWORD
429-
APIENTRY
430-
NtUserGetRawInputDeviceList(
431-
PRAWINPUTDEVICELIST pRawInputDeviceList,
432-
PUINT puiNumDevices,
433-
UINT cbSize)
434-
{
435-
STUB;
436-
return 0;
437-
}
438-
439-
DWORD
440-
APIENTRY
441-
NtUserGetRegisteredRawInputDevices(
442-
PRAWINPUTDEVICE pRawInputDevices,
443-
PUINT puiNumDevices,
444-
UINT cbSize)
445-
{
446-
STUB;
447-
return 0;
448-
}
449-
450391
DWORD
451392
APIENTRY
452393
NtUserHardErrorControl(
@@ -635,17 +576,6 @@ NtUserRealWaitMessageEx(
635576
return 0;
636577
}
637578

638-
BOOL
639-
APIENTRY
640-
NtUserRegisterRawInputDevices(
641-
IN PCRAWINPUTDEVICE pRawInputDevices,
642-
IN UINT uiNumDevices,
643-
IN UINT cbSize)
644-
{
645-
STUB;
646-
return 0;
647-
}
648-
649579
DWORD APIENTRY
650580
NtUserResolveDesktopForWOW(DWORD Unknown0)
651581
{

0 commit comments

Comments
 (0)