{"id":18556688,"url":"https://github.com/valkryst/vcontroller","last_synced_at":"2025-05-15T13:33:33.905Z","repository":{"id":142749637,"uuid":"105666218","full_name":"Valkryst/VController","owner":"Valkryst","description":"A helper library for JInput which makes it easy to automatically poll for controller input, connection, and disconnection events and notify listeners when they occur.","archived":false,"fork":false,"pushed_at":"2024-01-21T16:00:31.000Z","size":287,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-17T11:34:10.287Z","etag":null,"topics":["controller","controller-api","controller-manager","game-dev","game-development","gamedev","hacktoberfest","jinput","roguelike","roguelike-library","roguelikedev","usb"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Valkryst.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"Valkryst"}},"created_at":"2017-10-03T15:08:54.000Z","updated_at":"2024-02-29T15:21:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"e27250e8-1b6b-496c-865b-09b10e1b8154","html_url":"https://github.com/Valkryst/VController","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Valkryst%2FVController","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Valkryst%2FVController/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Valkryst%2FVController/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Valkryst%2FVController/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Valkryst","download_url":"https://codeload.github.com/Valkryst/VController/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254349276,"owners_count":22056312,"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":["controller","controller-api","controller-manager","game-dev","game-development","gamedev","hacktoberfest","jinput","roguelike","roguelike-library","roguelikedev","usb"],"created_at":"2024-11-06T21:32:52.708Z","updated_at":"2025-05-15T13:33:33.855Z","avatar_url":"https://github.com/Valkryst.png","language":"Java","readme":"[![Java CI with Maven](https://github.com/Valkryst/VController/actions/workflows/maven.yml/badge.svg)](https://github.com/Valkryst/VController/actions/workflows/maven.yml)\n[![CodeQL](https://github.com/Valkryst/VController/actions/workflows/codeql.yml/badge.svg)](https://github.com/Valkryst/VController/actions/workflows/codeql.yml)\n\nVController is a helper library for [JInput](https://github.com/jinput/jinput) with the following features:\n\n* Automatic polling of controller input events VIA [ControllerPoller](https://github.com/Valkryst/VController/blob/master/src/main/java/com/valkryst/VController/ControllerPoller.java).\n* Automatic detection of controller connection and disconnection events VIA [HotSwapPoller](https://github.com/Valkryst/VController/blob/master/src/main/java/com/valkryst/VController/HotSwapPoller.java).\n  * As JInput does not natively support hot-swapping, this library uses a polling approach to detect it. The downside to this approach is that JInput may print messages to `System.err` on every poll. \n  * **This _will_ cause a resource leak on Windows. A solution is being discussed [here](https://github.com/Valkryst/VController/issues/6).**\n    * To mitigate this issue, I suggest only enabling the `HotSwapPoller` when showing the user a list of controllers to select from. Reducing the polling rate will also help as each poll creates a \"dead\" thread which takes up system resources.\n* Interfaces to listen to controller and hot-swap events VIA [ControllerListener](https://github.com/Valkryst/VController/blob/master/src/main/java/com/valkryst/VController/ControllerListener.java) and [HotSwapListener](https://github.com/Valkryst/VController/blob/master/src/main/java/com/valkryst/VController/HotSwapListener.java).\n\nThis library assumes that you have already [properly configured](https://jinput.github.io/jinput/) JInput and that it is working.\n\n## Table of Contents\n\n* [Installation](https://github.com/Valkryst/VController#installation)\n    * [Gradle](https://github.com/Valkryst/VController#-gradle)\n    * [Maven](https://github.com/Valkryst/VController#-maven)\n    * [sbt](https://github.com/Valkryst/VController#-scala-sbt)\n* [Example](https://github.com/Valkryst/VController#example)\n  * [Controller Polling](https://github.com/Valkryst/VController#controller-polling) \n  * [Hot Swap Polling](https://github.com/Valkryst/VController#hot-swap-polling) \n\n## Installation\n\nVController is hosted on the [JitPack package repository](https://jitpack.io/#Valkryst/VController)\nwhich supports Gradle, Maven, and sbt.\n\n### ![Gradle](https://i.imgur.com/qtc6bXq.png?1) Gradle\n\nAdd JitPack to your `build.gradle` at the end of repositories.\n\n```\nallprojects {\n\trepositories {\n\t\t...\n\t\tmaven { url 'https://jitpack.io' }\n\t}\n}\n```\n\nAdd VController as a dependency.\n\n```\ndependencies {\n\timplementation 'com.github.Valkryst:VController:2023.10.26'\n}\n```\n\n### ![Maven](https://i.imgur.com/2TZzobp.png?1) Maven\n\nAdd JitPack as a repository.\n\n``` xml\n\u003crepositories\u003e\n    \u003crepository\u003e\n        \u003cid\u003ejitpack.io\u003c/id\u003e\n        \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n```\nAdd VController as a dependency.\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.Valkryst\u003c/groupId\u003e\n    \u003cartifactId\u003eVController\u003c/artifactId\u003e\n    \u003cversion\u003e2023.10.26\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### ![Scala SBT](https://i.imgur.com/Nqv3mVd.png?1) Scala SBT\n\nAdd JitPack as a resolver.\n\n```\nresolvers += \"jitpack\" at \"https://jitpack.io\"\n```\n\nAdd VController as a dependency.\n\n```\nlibraryDependencies += \"com.github.Valkryst\" % \"VController\" % \"2023.10.26\"\n```\n\n## Example\n\n### Controller Polling\n\nThis example prompts you to select a controller, then it continuously polls the controller for events and prints them to the console.\n\n```java\nimport net.java.games.input.Controller;\nimport net.java.games.input.ControllerEnvironment;\n\nimport java.util.Scanner;\n\npublic class ControllerExample {\n    public static void main(String[] args) {\n        final var controllerPoller = new ControllerPoller(getController());\n        controllerPoller.addListener(event -\u003e {\n            final var component = event.getComponent();\n            System.out.println(component.getName());\n            System.out.println(component.getIdentifier());\n            System.out.println(component.getDeadZone());\n            System.out.println(component.getPollData());\n            System.out.println();\n        });\n        controllerPoller.start(16);\n\n        System.out.println(\"\\nPolling for events. Try moving the controller's joysticks and pressing its buttons.\");\n    }\n\n    private static ControllerEnvironment getEnvironment() {\n        final var environment = ControllerEnvironment.getDefaultEnvironment();\n\n        if (!environment.isSupported()) {\n            throw new IllegalStateException(\"Controller environment is not supported.\");\n        }\n\n        return environment;\n    }\n\n    private static Controller getController() {\n        final var environment = getEnvironment();\n        final var controllers = environment.getControllers();\n\n        System.out.println(\"Detected Controllers\");\n        for (int i = 0 ; i \u003c controllers.length ; i++) {\n            System.out.println(\"\\t\" + i + \": \" + controllers[i].getName());\n        }\n\n        System.out.print(\"\\nEnter a number to select a controller: \");\n        final var scanner = new Scanner(System.in);\n        final var index = scanner.nextInt();\n        System.out.println(\"\\nYou selected: \" + controllers[index].getName());\n\n        return controllers[index];\n    }\n}\n```\n\n### Hot Swap Polling\n\nThis example prints a message to the console when a controller is connected or disconnected.\n\n```java\nimport net.java.games.input.Controller;\n\npublic class HotSwapExample {\n    public static void main(final String[] args) {\n        final var hotswapPoller = HotSwapPoller.getInstance();\n        hotswapPoller.addListener(new HotSwapListener() {\n            @Override\n            public void controllerAdded(Controller controller) {\n                System.out.println(\"Added: \" + controller.getName());\n            }\n\n            @Override\n            public void controllerRemoved(Controller controller) {\n                System.out.println(\"Removed: \" + controller.getName());\n            }\n        });\n\n        hotswapPoller.start();\n\n        System.out.println(\"Polling for hot-swaps. Try adding or removing a controller.\");\n    }\n}\n```\n\n## Credits \u0026 Inspiration\n\n* [litiengine](https://github.com/gurkenlabs/litienginehttps://github.com/gurkenlabs/litiengine)\n","funding_links":["https://github.com/sponsors/Valkryst"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalkryst%2Fvcontroller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalkryst%2Fvcontroller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalkryst%2Fvcontroller/lists"}