private GetRawInputBuffer ( [ Data, [ Size, [ SizeHeader ) : INT | ||
Data | [ | |
Size | [ | |
SizeHeader | [ | |
return | INT |
public void Poll() { return; #if false // We will do a buffered read for all input devices and route the RawInput structures // to the correct 'ProcessData' handlers. First, we need to find out the size of the // buffer to allocate for the structures. Then we allocate the buffer and read the // structures, calling the correct handler for each one. Last, we free the allocated // buffer. int size = 0; Functions.GetRawInputBuffer(IntPtr.Zero, ref size, API.RawInputHeaderSize); size *= 256; IntPtr rin_data = Marshal.AllocHGlobal(size); while (true) { // Iterate reading all available RawInput structures and routing them to their respective // handlers. int num = Functions.GetRawInputBuffer(rin_data, ref size, API.RawInputHeaderSize); if (num == 0) { break; } else if (num < 0) { /*int error = Marshal.GetLastWin32Error(); * if (error == 122) * { * // Enlarge the buffer, it was too small. * AllocateBuffer(); * } * else * { * throw new ApplicationException(String.Format( * "GetRawInputBuffer failed with code: {0}", error)); * }*/ Debug.Print("GetRawInputBuffer failed with code: {0}", Marshal.GetLastWin32Error()); //AllocateBuffer(); break; } RawInput[] rin_structs = new RawInput[num]; IntPtr next_rin = rin_data; for (int i = 0; i < num; i++) { rin_structs[i] = (RawInput)Marshal.PtrToStructure(next_rin, typeof(RawInput)); switch (rin_structs[i].Header.Type) { case RawInputDeviceType.KEYBOARD: keyboardDriver.ProcessKeyboardEvent(rin_structs[i]); break; case RawInputDeviceType.MOUSE: mouseDriver.ProcessEvent(rin_structs[i]); break; } next_rin = Functions.NextRawInputStructure(next_rin); } Functions.DefRawInputProc(rin_structs, num, (uint)API.RawInputHeaderSize); } Marshal.FreeHGlobal(rin_data); #endif }