Mtf.Joystick 1.0.0

dotnet add package Mtf.Joystick --version 1.0.0                
NuGet\Install-Package Mtf.Joystick -Version 1.0.0                
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="Mtf.Joystick" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mtf.Joystick --version 1.0.0                
#r "nuget: Mtf.Joystick, 1.0.0"                
#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.
// Install Mtf.Joystick as a Cake Addin
#addin nuget:?package=Mtf.Joystick&version=1.0.0

// Install Mtf.Joystick as a Cake Tool
#tool nuget:?package=Mtf.Joystick&version=1.0.0                

JoystickHandler Class

The JoystickHandler class provides functionality to handle joystick input using the SharpDX.DirectInput library. It enables polling joystick states, reacting to axis movements, and triggering actions for button presses.

Namespace

Mtf.Joystick

Methods

InitializeJoystick

Initializes and starts listening to joystick input. It polls the joystick for its current state, interprets axis movements, and triggers associated actions.

Parameters
  • Func<bool> continuePulling: Function to determine if polling should continue.
  • Func<int> getDeltaModifier: Function to provide a value for scaling joystick axis movements.
  • Func<int> getMinimumDelta: Function to provide the minimum threshold for movement detection.
  • Action<int, int> restAction: Action to invoke when the joystick is at rest.
  • Action<int, int> forwardOrBackwardAction: Action to invoke for forward/backward movement.
  • Action<int, int> forwardWithLeftTurnAction: Action to invoke for forward with a left turn.
  • Action<int, int> forwardWithRightTurnAction: Action to invoke for forward with a right turn.
  • Action<int, int> backwardWithLeftTurnAction: Action to invoke for backward with a left turn.
  • Action<int, int> backwardWithRightTurnAction: Action to invoke for backward with a right turn.
  • Action<int, int> turnLeftOrRightAction: Action to invoke for turning left or right.
  • Action afterPullingAction: Action to invoke after polling stops.
  • Action[] buttonActions: Array of actions to invoke for button presses.
Returns
  • CancellationTokenSource: A token source to manage polling cancellation.

StopJoystick

Stops joystick polling.

Parameters
  • CancellationTokenSource joystickPollCancellationTokenSource: The token source managing the polling task.

Example Usage

Here is a simplified example demonstrating how to use the JoystickHandler:

using System;
using System.Threading;

var joystickPollCancellationTokenSource = JoystickHandler.InitializeJoystick(
    continuePulling: () => true,
    getDeltaModifier: () => 10,
    getMinimumDelta: () => 5,
    restAction: (deltaX, deltaY) => Console.WriteLine("Joystick at rest."),
    forwardOrBackwardAction: (deltaX, deltaY) => Console.WriteLine($"Moving forward/backward: {deltaY}"),
    forwardWithLeftTurnAction: (deltaX, deltaY) => Console.WriteLine($"Forward with left turn: {deltaX}, {deltaY}"),
    forwardWithRightTurnAction: (deltaX, deltaY) => Console.WriteLine($"Forward with right turn: {deltaX}, {deltaY}"),
    backwardWithLeftTurnAction: (deltaX, deltaY) => Console.WriteLine($"Backward with left turn: {deltaX}, {deltaY}"),
    backwardWithRightTurnAction: (deltaX, deltaY) => Console.WriteLine($"Backward with right turn: {deltaX}, {deltaY}"),
    turnLeftOrRightAction: (deltaX, deltaY) => Console.WriteLine($"Turning left/right: {deltaX}"),
    afterPullingAction: () => Console.WriteLine("Polling stopped."),
    buttonActions: new Action[]
    {
        () => Console.WriteLine("Button 1 pressed."),
        () => Console.WriteLine("Button 2 pressed."),
        () => Console.WriteLine("Button 3 pressed."),
    }
);

// Simulate stopping the joystick handler after some time
Thread.Sleep(5000);
JoystickHandler.StopJoystick(joystickPollCancellationTokenSource);

Notes

  1. The library uses SharpDX.DirectInput for device communication. Ensure the SharpDX library is installed.
  2. The joystick must be connected, and the DeviceClass.GameControl class is used to detect input devices.
  3. All movements and button presses are translated into corresponding actions, making this class versatile for various input scenarios.
  4. Remember to dispose of the cancellation token properly after stopping the joystick.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.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.0.0 99 11/17/2024