コード例 #1
0
ファイル: WinRawJoystick.cs プロジェクト: guusw/opentk
        unsafe void UpdateButtons(RawInput *rin, Device stick)
        {
            stick.ClearButtons();

            for (int i = 0; i < stick.ButtonCaps.Count; i++)
            {
                short * usage_list   = stackalloc short[(int)JoystickButton.Last + 1];
                int     usage_length = (int)JoystickButton.Last;
                HIDPage page         = stick.ButtonCaps[i].UsagePage;
                short   collection   = stick.ButtonCaps[i].LinkCollection;

                HidProtocolStatus status = HidProtocol.GetUsages(
                    HidProtocolReportType.Input,
                    page, 0, usage_list, ref usage_length,
                    PreparsedData,
                    new IntPtr((void *)&rin->Data.HID.RawData),
                    rin->Data.HID.Size);

                if (status != HidProtocolStatus.Success)
                {
                    Debug.Print("[WinRawJoystick] HidProtocol.GetUsages() failed with {0}",
                                Marshal.GetLastWin32Error());
                    continue;
                }

                for (int j = 0; j < usage_length; j++)
                {
                    short usage = *(usage_list + j);
                    stick.SetButton(collection, page, usage, true);
                }
            }
        }
コード例 #2
0
        private unsafe void UpdateButtons(RawInput *rin, Device stick)
        {
            stick.ClearButtons();

            for (var i = 0; i < stick.ButtonCaps.Count; i++)
            {
                short *usage_list   = stackalloc short[64];
                var    usage_length = 64;
                var    page         = stick.ButtonCaps[i].UsagePage;
                var    collection   = stick.ButtonCaps[i].LinkCollection;

                var status = HidProtocol.GetUsages(
                    HidProtocolReportType.Input,
                    page, 0, usage_list, ref usage_length,
                    PreparsedData,
                    new IntPtr(&rin->Data.Hid.RawData),
                    (int)rin->Data.Hid.SizeHid
                    );

                if (status != HidProtocolStatus.Success)
                {
                    Debug.Print("[WinRawJoystick] HidProtocol.GetUsages() failed with {0}",
                                Marshal.GetLastWin32Error());
                    continue;
                }

                for (var j = 0; j < usage_length; j++)
                {
                    var usage = *(usage_list + j);
                    stick.SetButton(collection, page, usage, true);
                }
            }
        }
コード例 #3
0
        public Form1()
        {
            WindowState   = FormWindowState.Minimized;
            ShowInTaskbar = false;
            InitializeComponent();
            AllocConsole();

            sz = 8192;
            ri = (RawInput *)Marshal.AllocHGlobal(8192);

            var regs = new RawInputDevice[] {
                new RawInputDevice {
                    UsagePage = HIDUsagePage.Generic,
                    Usage     = HIDUsage.Mouse,
                    Flags     = RawInputDeviceFlags.InputSink |
                                RawInputDeviceFlags.NoLegacy,
                    WindowHandle = this.Handle
                }
            };

            RegisterRawInputDevices(
                regs, regs.Length,
                Marshal.SizeOf(typeof(RawInputDevice))
                );
        }
コード例 #4
0
        public static unsafe void HandleMessage(IntPtr rawInputMessagePointer)
        {
            int cbSizeRef = 0;

            GetRawInputData(rawInputMessagePointer, RawInputDataType.Input, IntPtr.Zero, ref cbSizeRef, Utilities.SizeOf <RawInputHeader>());
            if (cbSizeRef == 0)
            {
                return;
            }
            byte *numPtr = stackalloc byte[cbSizeRef];

            GetRawInputData(rawInputMessagePointer, RawInputDataType.Input, (IntPtr)((void *)numPtr), ref cbSizeRef, Utilities.SizeOf <RawInputHeader>());
            RawInput *rawInputPtr = (RawInput *)numPtr;

            switch (rawInputPtr->Header.Type)
            {
            case DeviceType.Mouse:
                if (MouseInput != null)
                {
                    MouseInput(new MyMouseInputArgs(ref *rawInputPtr));
                }
                break;

            case DeviceType.Keyboard:
                if (KeyboardInput != null)
                {
                    KeyboardInput(new MyKeyboardInputArgs(ref *rawInputPtr));
                }
                break;

            case DeviceType.HumanInputDevice:
                ProcessRawInput(ref *rawInputPtr);
                break;
            }
        }
コード例 #5
0
        private unsafe void UpdateAxes(RawInput *rin, Device stick)
        {
            for (int i = 0; i < stick.AxisCaps.Count; i++)
            {
                if (stick.AxisCaps[i].IsRange)
                {
                    Debug.Print("[{0}] Axis range collections not implemented. Please report your controller type at https://github.com/opentk/opentk/issues",
                                GetType().Name);
                    continue;
                }

                HIDPage page       = stick.AxisCaps[i].UsagePage;
                short   usage      = stick.AxisCaps[i].NotRange.Usage;
                uint    value      = 0;
                short   collection = stick.AxisCaps[i].LinkCollection;

                HidProtocolStatus status = HidProtocol.GetUsageValue(
                    HidProtocolReportType.Input,
                    page, 0, usage, ref value,
                    PreparsedData,
                    new IntPtr((void *)&rin->Data.HID.RawData),
                    rin->Data.HID.Size);

                if (status != HidProtocolStatus.Success)
                {
                    Debug.Print("[{0}] HidProtocol.GetScaledUsageValue() failed. Error: {1}",
                                GetType().Name, status);
                    continue;
                }

                if (page == HIDPage.GenericDesktop && (HIDUsageGD)usage == HIDUsageGD.Hatswitch)
                {
                    stick.SetHat(collection, page, usage, GetHatPosition(value, stick.AxisCaps[i]));
                }
                else
                {
                    if (stick.AxisCaps[i].LogicalMin > 0)
                    {
                        short scaled_value = (short)HidHelper.ScaleValue(
                            (int)((long)value + stick.AxisCaps[i].LogicalMin),
                            stick.AxisCaps[i].LogicalMin, stick.AxisCaps[i].LogicalMax,
                            Int16.MinValue, Int16.MaxValue);
                        stick.SetAxis(collection, page, usage, scaled_value);
                    }
                    else
                    {
                        //If our stick returns a minimum value below zero, we should not add this to our value
                        //before attempting to scale it, as this then inverts the value
                        short scaled_value = (short)HidHelper.ScaleValue(
                            (int)(long)value,
                            stick.AxisCaps[i].LogicalMin, stick.AxisCaps[i].LogicalMax,
                            Int16.MinValue, Int16.MaxValue);
                        stick.SetAxis(collection, page, usage, scaled_value);
                    }
                }
            }
        }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: R030t1/WinInputRecorder
        public MainForm()
        {
            AppDomain.CurrentDomain.ProcessExit += Exited;

            sz = 8192;
            ri = (RawInput *)Marshal.AllocHGlobal(8192);
            fs = new FileStream(
                "inputrec.dat.gz",
                System.IO.FileMode.Append,
                System.IO.FileAccess.Write
                );
            gs = new GZipStream(fs, CompressionLevel.Optimal);

            InitializeComponent();
            AllocConsole();

            // Low-level hooks do not require an injectable DLL.
            // Using WH_KEYBOARD allows detection of per-application
            // keyboard translation information; no benefit is known
            // for WH_MOUSE.
            SetWindowsHookEx(
                WindowsHookType.WH_MOUSE_LL,
                LowLevelMouseProc,
                IntPtr.Zero, 0
                );

            var regs = new RawInputDevice[] {
                // TODO: Not getting scroll events on other windows?
                // Not getting *trackpad* scroll events.
                new RawInputDevice {
                    UsagePage = HIDUsagePage.Generic,
                    Usage     = HIDUsage.Mouse,
                    Flags     = RawInputDeviceFlags.InputSink |
                                RawInputDeviceFlags.NoLegacy,
                    WindowHandle = this.Handle
                },
                new RawInputDevice {
                    UsagePage    = HIDUsagePage.Generic,
                    Usage        = HIDUsage.Gamepad,
                    Flags        = RawInputDeviceFlags.InputSink,
                    WindowHandle = this.Handle
                },
                new RawInputDevice {
                    UsagePage    = HIDUsagePage.Digitizer,
                    Usage        = HIDUsage.Joystick,
                    Flags        = RawInputDeviceFlags.InputSink,
                    WindowHandle = this.Handle
                }
            };

            RegisterRawInputDevices(
                regs, regs.Length,
                Marshal.SizeOf(typeof(RawInputDevice))
                );
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: R030t1/windows-input-capture
        public Form1()
        {
            WindowState   = FormWindowState.Minimized;
            ShowInTaskbar = false;
            AllocConsole();

            llms = SetWindowsHookEx(WindowsHookType.WH_KEYBOARD_LL, LLKeyboardProc,
                                    GetModuleHandle(null), 0);
            llkb = SetWindowsHookEx(WindowsHookType.WH_MOUSE_LL, LLMouseProc,
                                    GetModuleHandle(null), 0);

            sz = 8192;
            ri = (RawInput *)Marshal.AllocHGlobal(8192);

            var regs = new RawInputDevice[] {
                new RawInputDevice {
                    UsagePage = HIDUsagePage.Generic,
                    Usage     = HIDUsage.Mouse,
                    Flags     = RawInputDeviceFlags.InputSink |
                                RawInputDeviceFlags.NoLegacy,
                    WindowHandle = this.Handle
                },
                new RawInputDevice {
                    UsagePage = HIDUsagePage.Generic,
                    Usage     = HIDUsage.Keyboard,
                    Flags     = RawInputDeviceFlags.InputSink |
                                RawInputDeviceFlags.NoLegacy,
                    WindowHandle = this.Handle
                }
            };

            RegisterRawInputDevices(
                regs, regs.Length,
                Marshal.SizeOf(typeof(RawInputDevice))
                );

            InitializeComponent();
        }
コード例 #8
0
ファイル: WinRawJoystick.cs プロジェクト: guusw/opentk
        public unsafe bool ProcessEvent(IntPtr raw)
        {
            // Query the size of the raw HID data buffer
            int size = 0;

            Functions.GetRawInputData(raw, GetRawInputDataEnum.INPUT, IntPtr.Zero, ref size, RawInputHeader.SizeInBytes);
            if (size > HIDData.Length)
            {
                Array.Resize(ref HIDData, size);
            }

            // Retrieve the raw HID data buffer
            if (Functions.GetRawInputData(raw, HIDData) > 0)
            {
                fixed(byte *pdata = HIDData)
                {
                    RawInput *rin = (RawInput *)pdata;

                    IntPtr handle = rin->Header.Device;
                    Device stick  = GetDevice(handle);

                    if (stick == null)
                    {
                        Debug.Print("[WinRawJoystick] Unknown device {0}", handle);
                        return(false);
                    }

                    if (stick.IsXInput)
                    {
                        return(true);
                    }

                    if (!GetPreparsedData(handle, ref PreparsedData))
                    {
                        return(false);
                    }

                    // Query current state
                    // Allocate enough storage to hold the data of the current report
                    int report_count = HidProtocol.MaxDataListLength(HidProtocolReportType.Input, PreparsedData);

                    if (report_count == 0)
                    {
                        Debug.Print("[WinRawJoystick] HidProtocol.MaxDataListLength() failed with {0}",
                                    Marshal.GetLastWin32Error());
                        return(false);
                    }

                    // Fill the data buffer
                    if (DataBuffer.Length < report_count)
                    {
                        Array.Resize(ref DataBuffer, report_count);
                    }

                    UpdateAxes(rin, stick);
                    UpdateButtons(rin, stick);
                    return(true);
                }
            }

            return(false);
        }
コード例 #9
0
ファイル: Functions.cs プロジェクト: conankzhang/fez
 internal static int GetRawInputData(IntPtr RawInput, GetRawInputDataEnum Command, RawInput *Data, [In, Out] ref int Size, int SizeHeader);