1 /* $Id: input.c,v 1.3 2002/09/17 23:43:28 dwelch Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * PURPOSE: Window classes
6 * FILE: subsys/win32k/ntuser/class.c
7 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
9 * 06-06-2001 CSH Created
12 /* INCLUDES ******************************************************************/
14 #include <ddk/ntddk.h>
15 #include <win32k/win32k.h>
16 #include <win32k/userobj.h>
17 #include <include/class.h>
18 #include <include/error.h>
19 #include <include/winsta.h>
20 #include <include/msgqueue.h>
21 #include "../../drivers/input/include/mouse.h"
26 /* GLOBALS *******************************************************************/
28 static HANDLE MouseDeviceHandle
;
29 static HANDLE KeyboardThreadHandle
;
30 static CLIENT_ID KeyboardThreadId
;
31 static HANDLE KeyboardDeviceHandle
;
32 static KEVENT InputThreadsStart
;
33 static BOOLEAN InputThreadsRunning
= FALSE
;
35 VOID
MouseGDICallBack(PMOUSE_INPUT_DATA Data
, ULONG InputCount
);
37 /* FUNCTIONS *****************************************************************/
39 NTSTATUS STDCALL STATIC
40 KeyboardThreadMain(PVOID StartContext
)
42 UNICODE_STRING KeyboardDeviceName
;
43 OBJECT_ATTRIBUTES KeyboardObjectAttributes
;
47 RtlInitUnicodeStringFromLiteral(&KeyboardDeviceName
, L
"\\??\\Keyboard");
48 InitializeObjectAttributes(&KeyboardObjectAttributes
,
53 Status
= NtOpenFile(&KeyboardDeviceHandle
,
55 &KeyboardObjectAttributes
,
59 if (!NT_SUCCESS(Status
))
61 DbgPrint("W32K: Failed to open keyboard.\n");
68 * Wait to start input.
70 Status
= KeWaitForSingleObject(&InputThreadsStart
,
76 * Receive and process keyboard input.
78 while (InputThreadsRunning
)
80 KEY_EVENT_RECORD KeyEvent
;
83 Status
= NtReadFile (KeyboardDeviceHandle
,
89 sizeof(KEY_EVENT_RECORD
),
92 if (Status
== STATUS_ALERTED
&& !InputThreadsRunning
)
96 if (!NT_SUCCESS(Status
))
98 DbgPrint("W32K: Failed to read from keyboard.\n");
103 * Post a keyboard message.
105 if (KeyEvent
.bKeyDown
)
107 /* FIXME: Bit 24 indicates if this is an extended key. */
108 lParam
= KeyEvent
.wRepeatCount
|
109 ((KeyEvent
.wVirtualScanCode
<< 16) & 0x00FF0000) | 0x40000000;
110 MsqPostKeyboardMessage(WM_KEYDOWN
, KeyEvent
.wVirtualKeyCode
,
115 /* FIXME: Bit 24 indicates if this is an extended key. */
116 lParam
= KeyEvent
.wRepeatCount
|
117 ((KeyEvent
.wVirtualScanCode
<< 16) & 0x00FF0000) | 0xC0000000;
118 MsqPostKeyboardMessage(WM_KEYUP
, KeyEvent
.wVirtualKeyCode
,
126 NtUserAcquireOrReleaseInputOwnership(BOOLEAN Release
)
128 if (Release
&& InputThreadsRunning
)
130 KeClearEvent(&InputThreadsStart
);
131 InputThreadsRunning
= FALSE
;
132 NtAlertThread(KeyboardThreadHandle
);
134 else if (!Release
&& !InputThreadsRunning
)
136 InputThreadsRunning
= TRUE
;
137 KeSetEvent(&InputThreadsStart
, IO_NO_INCREMENT
, FALSE
);
139 return(STATUS_SUCCESS
);
146 UNICODE_STRING MouseDeviceName
;
147 OBJECT_ATTRIBUTES MouseObjectAttributes
;
148 IO_STATUS_BLOCK Iosb
;
150 PFILE_OBJECT FileObject
;
151 GDI_INFORMATION GdiInfo
;
153 PIO_STACK_LOCATION StackPtr
;
155 KeInitializeEvent(&InputThreadsStart
, NotificationEvent
, FALSE
);
157 Status
= PsCreateSystemThread(&KeyboardThreadHandle
,
164 if (!NT_SUCCESS(Status
))
166 DbgPrint("W32K: Failed to create keyboard thread.\n");
167 NtClose(KeyboardThreadHandle
);
171 * Connect to the mouse class driver.
173 RtlInitUnicodeStringFromLiteral(&MouseDeviceName
, L
"\\??\\MouseClass");
174 InitializeObjectAttributes(&MouseObjectAttributes
,
179 Status
= NtOpenFile(&MouseDeviceHandle
,
181 &MouseObjectAttributes
,
185 if (!NT_SUCCESS(Status
))
187 DbgPrint("W32K: Failed to open mouse.\n");
190 Status
= ObReferenceObjectByHandle(MouseDeviceHandle
,
191 FILE_READ_DATA
| FILE_WRITE_DATA
,
194 (PVOID
*) &FileObject
,
197 if (!NT_SUCCESS(Status
))
199 DbgPrint("W32K: Failed to reference mouse file object.\n");
202 KeInitializeEvent(&IoEvent
, FALSE
, NotificationEvent
);
203 GdiInfo
.CallBack
= MouseGDICallBack
;
204 Irp
= IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_MOUSE_CONNECT
,
205 FileObject
->DeviceObject
,
213 StackPtr
= IoGetNextIrpStackLocation(Irp
);
214 StackPtr
->FileObject
= FileObject
;
215 StackPtr
->DeviceObject
= FileObject
->DeviceObject
;
216 StackPtr
->Parameters
.DeviceIoControl
.InputBufferLength
= sizeof(GdiInfo
);
217 StackPtr
->Parameters
.DeviceIoControl
.OutputBufferLength
= 0;
219 Status
= IoCallDriver(FileObject
->DeviceObject
, Irp
);
220 if (Status
== STATUS_PENDING
)
222 KeWaitForSingleObject(&FileObject
->Event
, Executive
, KernelMode
, FALSE
,
224 Status
= Iosb
.Status
;
226 if (!NT_SUCCESS(Status
))
228 DbgPrint("W32K: Failed to connect to mouse driver.\n");
232 return(STATUS_SUCCESS
);
236 CleanupInputImp(VOID
)
238 return(STATUS_SUCCESS
);