Toolbelt.Blazor.Gamepad 6.0.0

gamepad API access for your Blazor apps.

This package is considered a SemVer 2.0.0 package as it has a package dependency on SemVer 2.0.0 package(s).
This package will only be available to download with SemVer 2.0.0 compatible NuGet clients, such as Visual Studio 2017 (version 15.3) and above or NuGet client 4.3.0 and above. Read more
Install-Package Toolbelt.Blazor.Gamepad -Version 6.0.0
dotnet add package Toolbelt.Blazor.Gamepad --version 6.0.0
<PackageReference Include="Toolbelt.Blazor.Gamepad" Version="6.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Toolbelt.Blazor.Gamepad --version 6.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Blazor Gamepad NuGet Package

Summary

This is a class library that provides gamepad API access for your Blazor apps.

Requirements

Blazor v.3.0.0 Preview 9.

How to install and use?

1. Installation and Registration

Step.1 Install the library via NuGet package, like this.

>  dotnet add package Toolbelt.Blazor.Gamepad

Step.2 Register "GamepadList" service into the DI container, at ConfigureService method in the Startup class of your Blazor application.

using Toolbelt.Blazor.Extensions.DependencyInjection; // <- Add this line, and...
...
public class Startup
{
  public void ConfigureServices(IServiceCollection services)
  {
    services.AddGamepadList(); // <- Add this line.
    ...

2. Usage in your Blazor component (.razor)

Step.1 Inject the GamepadList service into the component.

@inject Toolbelt.Blazor.Gamepad.GamepadList GamepadList @* <- Add this. *@
...

Step.2 Invoke GetGamepadsAsync() async method to retreive gamepad list, and find a active gamepad object.

After you find it, you can reference gamepad axes and buttons.

Note: GetGamepadsAsync() returns empty list until any gamepad devices are activated. To activate the gamepad, you should do any actions on the gamepad device while the browser's document has focus.

Sample .razor code is here:

@page "/"
@using Toolbelt.Blazor.Gamepad
@using System.Timers
@implements IDisposable
@inject GamepadList GamePadList

@if (this.Gamepad != null) {
  <p>Axes</p>
  <ul>
    @foreach (var ax in this.Gamepad.Axes) {
      <li>@ax.ToString("#,0.0")</li>
    }
  </ul>

  <p>Buttons</p>
  <ul>
    @foreach (var button in this.Gamepad.Buttons) {
      <li>@button.Pressed (@button.Value)</li>
    }
  </ul>
}

@code {

  Gamepad Gamepad;

  Timer Timer = new Timer(200) { Enabled = true };

  protected override void OnInitialized() {
    Timer.Elapsed += Timer_Elapsed;
  }

  async void Timer_Elapsed(object sender, EventArgs args) {
    var gamepads = await GamePadList.GetGamepadsAsync();
    this.Gamepad = gamepads.FirstOrDefault();
    this.StateHasChanged();
  }

  public void Dispose() {
    Timer.Elapsed -= Timer_Elapsed;
    Timer.Dispose();
  }
}

Release Note

  • v.6.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 9 (not compatible with v.3.0.0 Preview 8 or before.)
  • v.5.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 6 (not compatible with v.3.0.0 Preview 5 or before.)
  • v.4.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 4 (not compatible with v.0.9.0 or before.)
  • v.3.0.0 - BREAKING CHANGE: Support Blazor v.0.9.0 (not compatible with v.0.8.0 or before.)
  • v.2.0.0 - BREAKING CHANGE: Support Blazor v.0.8.0 (not compatible with v.0.7.0 or before.)
  • v.1.0.0 - 1st release.

License

Mozilla Public License Version 2.0

Blazor Gamepad NuGet Package

Summary

This is a class library that provides gamepad API access for your Blazor apps.

Requirements

Blazor v.3.0.0 Preview 9.

How to install and use?

1. Installation and Registration

Step.1 Install the library via NuGet package, like this.

>  dotnet add package Toolbelt.Blazor.Gamepad

Step.2 Register "GamepadList" service into the DI container, at ConfigureService method in the Startup class of your Blazor application.

using Toolbelt.Blazor.Extensions.DependencyInjection; // <- Add this line, and...
...
public class Startup
{
  public void ConfigureServices(IServiceCollection services)
  {
    services.AddGamepadList(); // <- Add this line.
    ...

2. Usage in your Blazor component (.razor)

Step.1 Inject the GamepadList service into the component.

@inject Toolbelt.Blazor.Gamepad.GamepadList GamepadList @* <- Add this. *@
...

Step.2 Invoke GetGamepadsAsync() async method to retreive gamepad list, and find a active gamepad object.

After you find it, you can reference gamepad axes and buttons.

Note: GetGamepadsAsync() returns empty list until any gamepad devices are activated. To activate the gamepad, you should do any actions on the gamepad device while the browser's document has focus.

Sample .razor code is here:

@page "/"
@using Toolbelt.Blazor.Gamepad
@using System.Timers
@implements IDisposable
@inject GamepadList GamePadList

@if (this.Gamepad != null) {
  <p>Axes</p>
  <ul>
    @foreach (var ax in this.Gamepad.Axes) {
      <li>@ax.ToString("#,0.0")</li>
    }
  </ul>

  <p>Buttons</p>
  <ul>
    @foreach (var button in this.Gamepad.Buttons) {
      <li>@button.Pressed (@button.Value)</li>
    }
  </ul>
}

@code {

  Gamepad Gamepad;

  Timer Timer = new Timer(200) { Enabled = true };

  protected override void OnInitialized() {
    Timer.Elapsed += Timer_Elapsed;
  }

  async void Timer_Elapsed(object sender, EventArgs args) {
    var gamepads = await GamePadList.GetGamepadsAsync();
    this.Gamepad = gamepads.FirstOrDefault();
    this.StateHasChanged();
  }

  public void Dispose() {
    Timer.Elapsed -= Timer_Elapsed;
    Timer.Dispose();
  }
}

Release Note

  • v.6.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 9 (not compatible with v.3.0.0 Preview 8 or before.)
  • v.5.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 6 (not compatible with v.3.0.0 Preview 5 or before.)
  • v.4.0.0 - BREAKING CHANGE: Support Blazor v.3.0.0 Preview 4 (not compatible with v.0.9.0 or before.)
  • v.3.0.0 - BREAKING CHANGE: Support Blazor v.0.9.0 (not compatible with v.0.8.0 or before.)
  • v.2.0.0 - BREAKING CHANGE: Support Blazor v.0.8.0 (not compatible with v.0.7.0 or before.)
  • v.1.0.0 - 1st release.

License

Mozilla Public License Version 2.0

Release Notes

v.6.0.0
- BREAKING CHANGE: Support Blazor v.3.0.0 Preview 9 (not compatible with v.3.0.0 Preview 8 or before.)
v.5.0.0
- BREAKING CHANGE: Support Blazor v.3.0.0 Preview 6 (not compatible with v.3.0.0 Preview 5 or before.)
v.4.0.0
- BREAKING CHANGE: Support Blazor v.3.0.0 (not compatible with v.0.9.0 or before.)
v.3.0.0
- BREAKING CHANGE: Support Blazor v.0.9.0 (not compatible with v.0.8.0 or before.)
v.2.0.0
- BREAKING CHANGE: Support Blazor v.0.8.0 (not compatible with v.0.7.0 or before.)
v.1.0.0
- 1st release.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
6.0.0 31 9/6/2019
5.0.0 46 6/16/2019
4.0.0 87 5/2/2019
3.0.0 95 3/9/2019
2.0.0 105 2/10/2019
1.0.0 162 10/12/2018