{"id":13466656,"url":"https://github.com/jsakamoto/Toolbelt.Blazor.Gamepad","last_synced_at":"2025-03-26T00:31:25.445Z","repository":{"id":66230931,"uuid":"152745934","full_name":"jsakamoto/Toolbelt.Blazor.Gamepad","owner":"jsakamoto","description":"gamepad API access for your Blazor apps.","archived":false,"fork":false,"pushed_at":"2024-06-06T23:41:39.000Z","size":31106,"stargazers_count":30,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-04T09:02:59.018Z","etag":null,"topics":["blazor","blazor-extensions","gamepad","gamepad-api"],"latest_commit_sha":null,"homepage":"https://jsakamoto.github.io/Toolbelt.Blazor.Gamepad/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsakamoto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-12T12:17:41.000Z","updated_at":"2024-06-06T23:40:37.000Z","dependencies_parsed_at":"2024-06-07T00:57:25.127Z","dependency_job_id":null,"html_url":"https://github.com/jsakamoto/Toolbelt.Blazor.Gamepad","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsakamoto%2FToolbelt.Blazor.Gamepad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsakamoto%2FToolbelt.Blazor.Gamepad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsakamoto%2FToolbelt.Blazor.Gamepad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsakamoto%2FToolbelt.Blazor.Gamepad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsakamoto","download_url":"https://codeload.github.com/jsakamoto/Toolbelt.Blazor.Gamepad/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245566098,"owners_count":20636390,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blazor","blazor-extensions","gamepad","gamepad-api"],"created_at":"2024-07-31T15:00:47.843Z","updated_at":"2025-03-26T00:31:20.435Z","avatar_url":"https://github.com/jsakamoto.png","language":"C#","funding_links":[],"categories":["Libraries \u0026 Extensions"],"sub_categories":["Tools \u0026 Utilities"],"readme":"# Blazor Gamepad [![NuGet Package](https://img.shields.io/nuget/v/Toolbelt.Blazor.Gamepad.svg)](https://www.nuget.org/packages/Toolbelt.Blazor.Gamepad/)\n\n## Summary\n\nThis is a class library that provides gamepad API access for your Blazor apps.\n\n- _**Live Demo Site:**_ https://jsakamoto.github.io/Toolbelt.Blazor.Gamepad/\n\n![demo movie](https://raw.githubusercontent.com/jsakamoto/Toolbelt.Blazor.Gamepad/master/.assets/movie-001.gif)\n\n## Requirements\n\n\"Blazor Gamepad\" ver.9.x or later supports Blazor versions below.\n\n- v.6.0, 7.0, 8.0 or later\n\n\u003e **Note:**  \n\u003e If you are using Blazor version 5.0 or earlier, please use \"Blazor Gamepad\" ver.8.x or earlier.\n\nBoth \"Blazor WebAssembly App\" and \"Blazor Server App\" are supoorted.\n\n## How to install and use?\n\n### 1. Installation and Registration\n\n**Step.1** Install the library via NuGet package, like this.\n\n```shell\n\u003e dotnet add package Toolbelt.Blazor.Gamepad\n```\n\n**Step.2** Register \"GamepadList\" service into the DI container.\n\n```csharp\n// Program.cs\n...\nusing Toolbelt.Blazor.Extensions.DependencyInjection; // \u003c- Add this line, and...\n...\nvar builder = WebAssemblyHostBuilder.CreateDefault(args);\n...\nbuilder.Services.AddGamepadList(); // \u003c- Add this line.\n...\n```\n\n### 2. Usage in your Blazor component (.razor)\n\n**Step.1** Inject the `GamepadList` service into the component.\n\n```html\n@inject Toolbelt.Blazor.Gamepad.GamepadList GamepadList @* \u003c- Add this. *@\n...\n```\n\n**Step.2** Invoke `GetGamepadsAsync()` async method to retreive gamepad list, and find a active gamepad object.\n\nAfter you find it, you can reference gamepad axes and buttons.\n\n_**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._\n\nSample .razor code is here:\n\n```csharp\n@page \"/\"\n@using Toolbelt.Blazor.Gamepad\n@using System.Timers\n@implements IDisposable\n@inject GamepadList GamePadList\n\n@if (this.Gamepad != null) {\n  \u003cp\u003eAxes\u003c/p\u003e\n  \u003cul\u003e\n    @foreach (var ax in _gamepad.Axes) {\n      \u003cli\u003e@ax.ToString(\"#,0.0\")\u003c/li\u003e\n    }\n  \u003c/ul\u003e\n\n  \u003cp\u003eButtons\u003c/p\u003e\n  \u003cul\u003e\n    @foreach (var button in _gamepad.Buttons) {\n      \u003cli\u003e@button.Pressed (@button.Value)\u003c/li\u003e\n    }\n  \u003c/ul\u003e\n}\n\n@code {\n\n  private Gamepad? _gamepad;\n\n  private readonly System.Timers.Timer _timer = new Timer(200) { Enabled = true };\n\n  protected override void OnInitialized() {\n    _timer.Elapsed += timer_Elapsed;\n  }\n\n  private async void timer_Elapsed(object sender, EventArgs args) {\n    var gamepads = await GamePadList.GetGamepadsAsync();\n    _gamepad = gamepads.FirstOrDefault();\n    if (_gamepad != null) \n      await this.InvokeAsync(() =\u003e this.StateHasChanged());\n  }\n\n  public void Dispose() {\n    _timer.Elapsed -= timer_Elapsed;\n    _timer.Dispose();\n  }\n}\n```\n\n## Configuration options\n\nThe calling of `AddGamepadList()` injects the reference of the helper JavaScript file (.js) - which are bundled with this package - into your page automatically.\n\nIf you don't want this behavior, you can disable the automatic injections. \nTo do that, please call `AddGamepadList()` with configuration action like this:\n\n```csharp\nbuilder.Services.AddGamepadList(options =\u003e\n{\n  // If you don't want automatic injection of js file, add below;\n  options.DisableClientScriptAutoInjection = true;\n});\n```\n\nYou can inject the helper JavaScript file manually. The URL of that JavaScript file is below:\n\n- `_content/Toolbelt.Blazor.Gamepad/script.min.js`\n\n## Release Notes\n\nThe release notes is [here.](https://github.com/jsakamoto/Toolbelt.Blazor.Gamepad/blob/master/RELEASE-NOTES.txt)\n\n## License\n\n[Mozilla Public License Version 2.0](https://github.com/jsakamoto/Toolbelt.Blazor.Gamepad/blob/master/LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsakamoto%2FToolbelt.Blazor.Gamepad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsakamoto%2FToolbelt.Blazor.Gamepad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsakamoto%2FToolbelt.Blazor.Gamepad/lists"}