Adding Gamepad Support without a Gamepad
If you think that some games are better played with a gamepad 🎮, you are not alone. You might want to play games on your Steam library with controller support, or due to the natural course of game development, there might be a time you’ll add gamepad controls to your awesome game. Whatever the case, if you don’t have an actual gamepad available at your disposal, then I have a solution for you:
This repository lets you to use your mobile device/phone/tablet as a gamepad controller over Wi-Fi. Best part is that it is web-based and platform-independent, so you don’t have to install any app. It runs on node.js. It even provides haptic feedback on input! (Although not when triggered by the game, perhaps I should add that.)
Note that it does not support:
- trigger buttons (L2/R2 or LT/RT),
- D-pad
- Right joystick
so key remapping is required prior to use in games.
Demo
Single controller:
Three controllers:
Credit to Jérémy Hervy
Details
The original repository supports Linux OS, so I forked the master
branch and created a new windows
branch to add Windows OS support.
This version enables XInput gamepad input on Windows machines via the Node.js ViGEmClient package. Note: Node.js 14
is tested and supported.
Expectedly, my implementation differs a bit from the original:
Major changes:
- Downgraded ‘forever-monitor’ to 1.0.0 from 2.0.0, see this.
- No CoffeeScript since I was not familiar with it.
- Dependencies:
- Added: “vigemclient: 1.1.2”
- Removed: “ioctl”, “ref”, “ref-struct” and “ref-array”
- Added ‘virtual_gamepad_hub_vigem.js’ and ‘virtual_gamepad_vigem.js’.
- Edited ‘server.js’.
TODO: Implement keyboard and touchpad input, improve gamepad code, refactor, etc.
Later, @hifihedgehog forked my branch to make further improvements.
Added support for up to 10 controllers, up from 4, as implemented in the main branch of this project.
Check out the issue on original repository to see the full discussion: https://github.com/jehervy/node-virtual-gamepads/issues/80
Installation & Usage (Windows)
git clone https://github.com/hifihedgehog/node-virtual-gamepads
cd node-virtual-gamepads
npm install
node main.js
Access http://<PC_IP_ADDRESS>:PORT
from your mobile device(s). 🎮
By default, PORT
: 80
Optionally, you can edit config.json
to tweak the settings before launching the application.
You can test the gamepad: https://gamepad-tester.com/
The app can also be automatically launched as a windowless startup application (thanks @hifihedgehog for the tip):
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.CurrentDirectory = "C:\node-virtual-gamepads-windows\"
'Edit to your configuration ^ '
objShell.Run("""node"" main.js"), 0
Set objShell = Nothing
Throw this text into a .VBS script file and it will do the trick! Then just copy that file to your Start Menu startup folder (for all users, that would be C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup) and you are good to go.