Пример #1
0
        private static void KeyboardPressReleaseHelper(KeyEventArgs e, bool isPress)
        {
            uint ps2ScanCode = MapVirtualKeyA((uint)e.KeyValue, 0);
            byte hidScanCode = HidHelper.GetHidUsageFromPs2Set1(ps2ScanCode);

            if (isPress && _keyboardMouse.KeyboardIsPressed(hidScanCode))
            {
                return;
            }
            if (hidScanCode == 0)
            {
                Console.WriteLine($"Cannot find corresponding HID code of " +
                                  $"KeyValue=0x{e.KeyValue:X2}, PS/2={ps2ScanCode:X2}!");
                return;
            }
            GeneralPurposeStopwatch.Restart();
            try
            {
                (isPress ? _keyboardMouse.KeyboardPress(hidScanCode) : _keyboardMouse.KeyboardRelease(hidScanCode)).GetAwaiter().GetResult();
            }
            catch (SerialDeviceException ex)
            {
                Console.WriteLine($"Serial device overload:{ex.Message}, input: 0x{hidScanCode:X2}.");
                return;
            }
            GeneralPurposeStopwatch.Stop();
            Console.Write(isPress ? "Press" : "Release");
            Console.WriteLine($" keyboard HID=0x{hidScanCode:X2}, PS/2=0x{ps2ScanCode:X2}, Win32VK=0x{e.KeyValue:X2}. Timing: {GeneralPurposeStopwatch.ElapsedMicrosecond()} us.");
        }
Пример #2
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);
                    }
                }
            }
        }
Пример #3
0
            JoystickAxis GetAxis(short collection, HIDPage page, short usage)
            {
                int key = MakeKey(collection, page, usage);

                if (!axes.ContainsKey(key))
                {
                    JoystickAxis axis = HidHelper.TranslateJoystickAxis(page, usage);
                    axes.Add(key, axis);
                }
                return(axes[key]);
            }