{"id":31768912,"url":"https://github.com/tlabaltoh/ps4.controller.raw-input.visualizer-mapper","last_synced_at":"2025-10-10T02:20:55.301Z","repository":{"id":317059309,"uuid":"1065676321","full_name":"TLabAltoh/ps4.controller.raw-input.visualizer-mapper","owner":"TLabAltoh","description":"PS4 Controller → Mouse \u0026 Keyboard Mapper","archived":false,"fork":false,"pushed_at":"2025-09-28T15:45:50.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-28T16:24:20.724Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TLabAltoh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-28T07:50:08.000Z","updated_at":"2025-09-28T15:45:53.000Z","dependencies_parsed_at":"2025-09-29T22:33:22.966Z","dependency_job_id":null,"html_url":"https://github.com/TLabAltoh/ps4.controller.raw-input.visualizer-mapper","commit_stats":null,"previous_names":["tlabaltoh/ps4.controller.raw-input.visualizer-mapper"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/TLabAltoh/ps4.controller.raw-input.visualizer-mapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TLabAltoh%2Fps4.controller.raw-input.visualizer-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TLabAltoh%2Fps4.controller.raw-input.visualizer-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TLabAltoh%2Fps4.controller.raw-input.visualizer-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TLabAltoh%2Fps4.controller.raw-input.visualizer-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TLabAltoh","download_url":"https://codeload.github.com/TLabAltoh/ps4.controller.raw-input.visualizer-mapper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TLabAltoh%2Fps4.controller.raw-input.visualizer-mapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002537,"owners_count":26083399,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-10-10T02:20:52.950Z","updated_at":"2025-10-10T02:20:55.291Z","avatar_url":"https://github.com/TLabAltoh.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ps4.controller.raw-input.visualizer-mapper\r\n\r\nA Windows console application that listens for input from a connected **PlayStation 4 (DualShock 4) controller** via the Windows Raw Input API and:\r\n\r\n* Visualizes controller state (sticks, triggers, buttons, D-pad, battery, raw HID bytes) in the console as ASCII art.\r\n* Maps controller input to **mouse** and **keyboard** input using `SendInput`, so you can drive applications with a DualShock 4.\r\n* Provides a compact **virtual keyboard** you can operate with the controller.\r\n\r\nThe program is intended as a developer / hobby tool for experimenting with controller-to-input mappings and for quickly testing how a PS4 controller can emulate keyboard/mouse input.\r\n\r\n---\r\n\r\n## Highlights / Quick overview\r\n\r\n* **Dual mode:** Visualizer (shows controller state) and Virtual Keyboard (compact, selectable QWERTY layout). Toggle with `TAB` or the controller `OPTIONS` button.\r\n* **Mappings (default):**\r\n\r\n  * Left stick → WASD (analog mapped to digital key presses with a deadzone)\r\n  * D-Pad → Arrow keys\r\n  * Right stick → Relative mouse movement (cubic scaling for fine control)\r\n  * R2 → Left mouse button (when pressed past threshold)\r\n  * L2 → Right mouse button (when pressed past threshold)\r\n  * Face buttons → configurable VK mappings (defaults shown below)\r\n* **Virtual keyboard controls:** Left stick to move selection, Cross to press, Square toggles sticky Shift, Circle = Backspace, Triangle = Space.\r\n* **ESC** quits the program. Pressing `v`/`k` on the physical keyboard will also switch to Visualizer/Virtual Keyboard respectively.\r\n* `R1` toggles the console window visibility (show/hide). The console is kept always-on-top.\r\n* `R3` switches IME modes when the virtual keyboard is enabled.\r\n\r\n---\r\n\r\n## Default mappings\r\n\r\nThese defaults are created in the program (`initFaceButtonMap()` and related code):\r\n\r\n* `SQUARE` → `'E'` (VK `0x45`) — example mapping (edit in code to change)\r\n* `CROSS`  → `Space` (VK `VK_SPACE`)\r\n* `CIRCLE` → `Left Ctrl` (VK `VK_LCONTROL`)\r\n* `TRIANGLE` → `Left Shift` (VK `VK_LSHIFT`)\r\n\r\n**Visualizer mode:** face buttons send those mapped keys as press/release events.\r\n\r\n**Virtual Keyboard mode:** face buttons are used for keyboard UI actions (regardless of the face-button map):\r\n\r\n* `Cross` — press selected virtual key\r\n* `Square` — toggle *sticky* Shift (Shift stays held by the emulator until toggled off)\r\n* `Circle` — Backspace\r\n* `Triangle` — Space\r\n\r\nYou can change the face button-to-VK mapping by editing the `faceButtonMap` initialization in the source.\r\n\r\n---\r\n\r\n## Virtual keyboard layout \u0026 behaviour\r\n\r\nA compact QWERTY-like layout (modifiable in source):\r\n\r\n```\r\nRow 0: Q W E R T Y U I O P\r\nRow 1: A S D F G H J K L ENTER\r\nRow 2: Z X C V B N M , . /\r\nRow 3: SPACE BACKSPACE\r\n```\r\n\r\n* Use the **left stick** to move the selection. The code implements a small repeat delay (`vkMoveDelayMs`, default 150 ms) so you can hold the stick for continuous movement.\r\n* Press **Cross** to emit the currently selected key via `SendInput`.\r\n* Press **Square** to toggle a sticky Shift state — while sticky Shift is on, subsequent key presses are sent with Shift down. The emulator physically holds and releases `VK_LSHIFT` for you.\r\n* Right stick **still controls the mouse** while in VK mode.\r\n\r\n**Note:** The virtual keyboard is intended for simple text entry and testing. It's not a full IME or localized input method; OEM keys and punctuation may differ between keyboard layouts.\r\n\r\n---\r\n\r\n## Building\r\n\r\nRequirements:\r\n\r\n* Windows 10 or later (32/64-bit). Raw Input and `SendInput` are Windows APIs.\r\n* Microsoft Visual C++ (MSVC) / Developer Command Prompt, or another C++17-capable compiler that targets Win32.\r\n\r\nOpen a **Developer Command Prompt for Visual Studio** and run one of the commands below (use the one that fits your toolchain):\r\n\r\n```bat\r\ncl /EHsc /std:c++17 main.cpp /link user32.lib\r\n```\r\n\r\nor (older MSVC; same effect):\r\n\r\n```bat\r\ncl /EHsc main.cpp /link user32.lib\r\n```\r\n\r\nThis produces `main.exe`.\r\n\r\n---\r\n\r\n## Running\r\n\r\n1. Connect your PS4 DualShock 4 controller via USB or pair it over Bluetooth.\r\n2. Launch the executable from a console window.\r\n3. Move sticks and press buttons — the console updates continuously with a visualization and mapping state.\r\n4. Toggle between **Visualizer** and **Virtual Keyboard** with `TAB` or by pressing the controller `OPTIONS` button. Press `ESC` to exit.\r\n5. Press `R1` to hide/show the console window at any time.\r\n\r\n---\r\n\r\n## Notable implementation details\r\n\r\n* **Raw Input:** the program registers a `RAWINPUTDEVICE` for `UsagePage=0x01` / `Usage=0x05` (Game Pad) with `RIDEV_INPUTSINK` so it receives input while the console does not have to be focused.\r\n* **HID parsing:** the program copies the first HID report into a packed `PS4ControllerReport` structure and uses fields such as `leftStickX`, `buttons1`, `leftTrigger`, `battery`, etc. Report layout (USB vs Bluetooth) can vary slightly across firmware/drivers — adjust the struct if your controller reports a different layout.\r\n* **SendInput:** keyboard and mouse events are generated with `SendInput`. This may be restricted by security or anti-cheat systems; synthetic input can be blocked or flagged by some applications.\r\n* **Mouse movement:** right stick movement is scaled with a cubic curve for finer low-speed control and multiplied by a `sensitivity` constant.\r\n* **Shift sticky:** when sticky Shift is enabled, the program holds `VK_LSHIFT` down until toggled off — this prevents rapid key-up/down behavior for shifted characters.\r\n* **Console window:** the console is set always-on-top on startup. Press `R1` to hide/show it.\r\n* **Key repeat:** `W/A/S/D` and Arrow keys auto-repeat while held (initial 300 ms, then every 70 ms).\r\n* **Mouse event coalescing:** uses `MOUSEEVENTF_MOVE_NOCOALESCE` to improve responsiveness of relative mouse movement.\r\n* **Triggers:** L2 and R2 map to right/left click when pressed past a threshold (default ≈ 50/255).\r\n* **Threading:** a background message thread owns a message-only window and receives Raw Input; the main thread performs mapping and console rendering to keep output single-threaded.\r\n\r\n---\r\n\r\n## Troubleshooting \u0026 known issues\r\n\r\n* **Different keyboard layouts:** OEM VK codes for punctuation (`, . / [ ] \\ - =`) depend on the physical keyboard layout. If you get unexpected characters from the virtual keyboard, modify `getVkForLabel()` in the source to match your layout.\r\n* **Stuck keys after crash/exit:** the program attempts to release any synthesized keys/buttons on exit. If it terminates abnormally (crash/kill), some keys may remain logically pressed by the OS. Reboot or use a small helper program to send key-up events if needed.\r\n* **Anti-cheat / protected focus applications:** Some games or protected windows ignore synthetic input sent with `SendInput` or may treat it as cheating. Use at your own risk and do not use in online or competitive environments.\r\n\r\n---\r\n\r\n## Sample console output\r\n\r\n```\r\n=== PS4 Controller -\u003e Mouse/Keyboard Mapper ===\r\nMappings (Visualizer mode):\r\n  Left stick -\u003e WASD (analog -\u003e digital)\r\n  D-Pad -\u003e Arrow keys\r\n  Right stick -\u003e Mouse movement (relative)\r\n  R2 -\u003e Left mouse button, L2 -\u003e Right mouse button\r\nControls:\r\nMode: VisualizerTAB to toggle Visualizer/Virtual Keyboard | OPTIONS button toggles too\r\n  In Virtual Keyboard: Left stick to move, Cross(X) to press, Square toggles Shift, Circle Backspace, Triangle Space, L3 JA/EN toggle\r\n\r\nMode: Visualizer\r\nLeft Stick:                   Right Stick:                  L2: [..........]   0\r\n...........                   ...........                   R2: [######....] 174\r\n..@........                   ...........\r\n.....+.....                   .....+.....                   Battery:   0\r\n...........                   .........@.\r\n...........                   ...........\r\nX:  52 Y:  61                 X: 235 Y: 203\r\n\r\nButtons:  SQR   CRO  [CIR]  TRI\r\nD-Pad: Neutral\r\n L1   R1   L3   R3   |  PS   PAD   SHARE   OPTIONS\r\nRaw Data: 01 34 3d eb cb 48 08 58 00 ae 4e c5 00 c7 ff fe ff fb ff 54 03 29 21 12\r\n```\r\n\r\n---\r\n\r\n## License\r\n\r\nThis project is released under the **MIT License**. See the `LICENSE.md` file for details.\r\n\r\n---\r\n\r\n## Where to modify behaviour\r\n\r\nCommon places to change functionality in the source:\r\n\r\n* `initFaceButtonMap()` — change face button → VK mappings.\r\n* `processVisualizerMapping()` / `processVirtualKeyboard()` — change how sticks/triggers/buttons are interpreted.\r\n* `getVkForLabel()` — add or adapt punctuation/OEM mappings for your locale.\r\n* Mouse sensitivity and deadzones are set in `processRightStickMouse()` and can be adjusted there.\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlabaltoh%2Fps4.controller.raw-input.visualizer-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftlabaltoh%2Fps4.controller.raw-input.visualizer-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlabaltoh%2Fps4.controller.raw-input.visualizer-mapper/lists"}