Skip to content

MaxRev-Dev/gamepad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gamepad

SNES Gamepad Controller

A simple gamepad controller with debouncer using SharpDX (DirectX). This project is similar to https://github.com/nahueltaibo/gamepad, but works in Windows using DirectX API.

Installation:

Install-Package MaxRev.Input.Gamepad 

Usage:

// See https://aka.ms/new-console-template for more information

using MaxRev.Input.Gamepad;

// Don't forget to dispose gamepad
using var gamepad = new GamepadController();
gamepad.AxisChanged += (s, e) =>
{
    Console.WriteLine($"Axis {e.Axis} - {e.Value}");
    // your own logic
};
gamepad.ButtonChanged += (s, e) =>
{
    Console.WriteLine($"Button {e.Button} - {e.Pressed}");
    // your own logic
};

You can also configure and attach a debouncer to handle longpress events:

// Debouncer can be optinally subscribed for input events
using var gamepad = new GamepadController();
using var inputDebouncer = new GamepadInputDebouncer(gamepad);
inputDebouncer.DebounceInterval = TimeSpan.FromMilliseconds(100);
inputDebouncer.LongPressInterval = TimeSpan.FromMilliseconds(250);
inputDebouncer.AxisLongPress += (s, e) =>
{
    Console.WriteLine($"Axis LongPress {e.Target.Axis} - x{e.Count}");
    // your own logic
};
inputDebouncer.ButtonLongPress += (s, e) =>
{
    Console.WriteLine($"Button LongPress {e.Target.Button} - x{e.Count}");
    // your own logic
};

Connected/Disconnected events:

By default controller awaits for gamepad to be reconnected.

using var gamepad = new GamepadController();
gamepad.AwaitForReconnection = true;
gamepad.OnDisconnected += (s) =>
{
    // Oh, crap! Gamepad was disconnected!
};
gamepad.OnReady += (s) =>
{
    // Gamepad was reconnected and ready to receive input!
};

Donations

Made with ❤️ in 🇺🇦

Our country needs any support, so you can donate to Armed Forces of Ukraine or humanitarian needs.

See more at https://standforukraine.com/

About

A SNES gamepad controller with debouncer using SharpDX (DirectX) written for .netstandard2.0

Resources

License

Stars

Watchers

Forks

Languages