XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Text.Json;
using Windows.Gaming.Input;
using System.Runtime.InteropServices;

// A bounded read-only controller-axis diagnostic. No keyboard, button values,
// vibration, input injection, game access or persistent device identifiers.
var samples = new List<object>();
var winMmSamples = new List<object>();
for (var sample = 0; sample < 6; sample++)
{
    foreach (var controller in RawGameController.RawGameControllers)
    {
        var axes = new double[controller.AxisCount];
        var buttons = new bool[controller.ButtonCount];
        var switches = new GameControllerSwitchPosition[controller.SwitchCount];
        var timestamp = controller.GetCurrentReading(buttons, switches, axes);
        samples.Add(new { at = DateTimeOffset.UtcNow, sample, controller = controller.DisplayName,
            axisCount = axes.Length, timestamp, axes });
    }
    for (uint id = 0; id < WinMm.joyGetNumDevs(); id++)
    {
        var state = new WinMm.JoyState { Size = (uint)Marshal.SizeOf<WinMm.JoyState>(), Flags = 0x3f };
        var result = WinMm.joyGetPosEx(id, ref state);
        if (result == 0) winMmSamples.Add(new { at = DateTimeOffset.UtcNow, sample, id,
            rawAxes = new[] { state.X, state.Y, state.Z, state.R, state.U, state.V } });
    }
    await Task.Delay(200);
}
Console.WriteLine(JsonSerializer.Serialize(new { observationOnly = true, keyboardRead = false, buttonValuesRecorded = false,
    gameAccessed = false, inputSent = false, samples, winMmSamples }, new JsonSerializerOptions { WriteIndented = true }));

internal static class WinMm
{
    [StructLayout(LayoutKind.Sequential)]
    internal struct JoyState { internal uint Size, Flags, X, Y, Z, R, U, V, Buttons, ButtonNumber, Pov, Reserved1, Reserved2; }
    [DllImport("winmm.dll")] internal static extern uint joyGetNumDevs();
    [DllImport("winmm.dll")] internal static extern uint joyGetPosEx(uint id, ref JoyState state);
}