{"id":24965801,"url":"https://github.com/jakubtomsu/gpad","last_synced_at":"2025-04-11T00:50:29.613Z","repository":{"id":274621794,"uuid":"651489808","full_name":"jakubtomsu/gpad","owner":"jakubtomsu","description":"Simple C/C++/Odin library for game controller input. Standalone SDL gamepad replacement for Windows.","archived":false,"fork":false,"pushed_at":"2025-01-28T11:44:28.000Z","size":341,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T21:38:46.385Z","etag":null,"topics":["game-development","odin-lang","single-header","stb-style"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jakubtomsu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-06-09T10:53:28.000Z","updated_at":"2025-02-23T23:05:29.000Z","dependencies_parsed_at":"2025-01-28T12:34:01.548Z","dependency_job_id":"67721058-c168-411a-b96a-4dbbe53a2511","html_url":"https://github.com/jakubtomsu/gpad","commit_stats":null,"previous_names":["jakubtomsu/gpad"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubtomsu%2Fgpad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubtomsu%2Fgpad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubtomsu%2Fgpad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakubtomsu%2Fgpad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jakubtomsu","download_url":"https://codeload.github.com/jakubtomsu/gpad/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322609,"owners_count":21084336,"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":["game-development","odin-lang","single-header","stb-style"],"created_at":"2025-02-03T11:16:40.675Z","updated_at":"2025-04-11T00:50:29.597Z","avatar_url":"https://github.com/jakubtomsu.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gpad\nSimple C/C++/Odin library for game controller input.\n\n\u003e [!WARNING]\n\u003e This library currently works only on windows, with support for XInput and DirectInput remapped using SDL controller DB. It's also missing support for device connected window messages.\n\u003e\n\u003e I am not planning to add more features. I didn't want to release this lib because it's unfinished, but now since some people asked me about it I decided to make it public anyway. That said any PRs are appreciated.\n\u003e To learn more about this topic I strongly recommend reading [Joystick Input Examples by MysteriousJ](https://github.com/MysteriousJ/Joystick-Input-Examples)\n\u003e\n\u003e Use at your own risk.\n\nAll raw device inputs are mapped to the Xbox controller layout.\n\n\n## Usage\nIn _only one_ C file, define `GPAD_IMPLEMENTATION`. Then you can just `#include \"gpad.h\"` anywhere else.\n```c\n#define GPAD_IMPLEMENTATION\n#include \"gpad.h\"\n```\n\nInit and shutdown context:\n```cpp\ngpad_initialize();\n\nwhile (true) {\n    // Tick ...\n}\n\ngpad_shutdown();\n```\n\nIterate all devices and poll their input:\n```cpp\nfor (int i = 0; i \u003c GPAD_MAX_DEVICES; i++) {\n    Gpad_Device_State state = {0};\n    // gpad_device_state will return false if the device on that ID is not connected.\n    if (gpad_device_state(i, \u0026state)) {\n        for(int button = 0; button \u003c Gpad_Button_COUNT; button++) {\n            printf(\"%s: %s\", gpad_button_name(button), gpad_device_button_pressed(\u0026state, button) ? \"down\" : \"up\");\n        }\n    }\n}\n```\n\nOr alternatively list all available devices using `gpad_list_devices` helper function.\n```cpp\nGpad_Device_Id devices[GPAD_MAX_DEVICES] = {0};\nint device_count = gpad_list_devices(\u0026devices[0], GPAD_MAX_DEVICES);\nfor (int i = 0; i \u003c device_count; i++) {\n    // use ID from device[i] ...\n}\n```\n\n## Examples\n\nThe examples are written in odinlang for simplicity, but should be easy enough to understand for a C programmer.\n\nRun with `odin run examples/some_example`.\n\nThe `visual` example is a simple raylib app which visualizes all the input states.\n\n## Build controller DB\nThis library uses [SDL Game Controller DB](https://github.com/gabomdq/SDL_GameControllerDB) to map raw joystick inputs to the Xbox controller layout. The `gamecontrollerdb.txt` contains the original data, and `build_db` is a program which  parses it and generates C code to `gpad_gamecontrollerdb.inl`.\n\nThe `build_db` tool is written in [Odin](https://github.com/odin-lang/Odin). To build the database, install Odin and run (from the gpad directory):\n```bat\nodin run build_db\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakubtomsu%2Fgpad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakubtomsu%2Fgpad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakubtomsu%2Fgpad/lists"}