GameInput.Net 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package GameInput.Net --version 1.0.3
                    
NuGet\Install-Package GameInput.Net -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GameInput.Net" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GameInput.Net" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="GameInput.Net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GameInput.Net --version 1.0.3
                    
#r "nuget: GameInput.Net, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GameInput.Net@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GameInput.Net&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=GameInput.Net&version=1.0.3
                    
Install as a Cake Tool

About

GameInput.Net is a .NET wrapper around Microsoft's GameInput library, a modern input capture system introduced woth the Microsoft Game Development Kit.

Prerequisites

You must have Windows 10 or 11 with the GameInput library installed. It is recommended you distribute the GameInput Redistributable with your software to ensure the user has the most recent version. GameInput.Net will look for the re-distributable before the boxed version.

This is included in the Microsoft.GameInput package, though not automatically installed.

How to Use

Download the package in your favorite IDE such as Jetbrains Rider or Microsoft Visual Studio using the NuGet package manager. You may also install via commandline dotnet tools.

dotnet add package GameInputNet

Compatible with .NET 6.0+ you can instantiate a GameInput object and access all of the native GameInput through the managed wrapper.

using GameInputDotNet;
using GameInputDotNet.Interop.Enums;

using var _gameInput = GameInput.Create();

// Set focus allow capture of inputs regardless of program focus.
_gameInput.SetFocusPolicy(GameInputFocusPolicy.EnableBackgroundInput);

while (true)
{
    // Slow down the loop so we don't get spammed.
    Thread.Sleep(100);
    GameInputReading? reading = null;

    try
    {
        // Get the current frame's "Keyboard" inputs.
        reading = _gameInput.GetCurrentReading(GameInputKind.Keyboard);
    }
    catch (GameInputException)
    {
        // Handle exceptions and unprepared reading from first frame.
        continue;
    }

    if (reading is null) continue;

    using (reading)
    {
        // Get the current state. 
        var state = reading.GetKeyboardState();

        // Nothing pressed we can jump to the next loop.
        if (state.Keys.Count == 0)
            continue;

        // Report the scan code of each key currently pressed.
        Console.Write("Keys Pressed: ");
        foreach (var key in state.Keys) Console.Write(key.ScanCode + " ");
        Console.WriteLine();

        // We can also use this to end our program when the user hits Escape.
        if (state.Keys.Any(key => key.ScanCode == 1))
        {
            Console.WriteLine("Got ESCAPE key, ending program.");
            break;
        }
    }
}

Documentation & Feedback

If you have issues or recommendations please submit a ticket through the GameInput.Net GitHub. The repo also contains additional documentation and examples.

Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.2 131 12/30/2025
1.0.3 314 11/12/2025
0.1.0-ops-setupNuGet.1 66 11/9/2025