Skip to content

About

Turn your phone into a wireless game controller for your PC.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฑ LAN Game Controller

Turn your phone into a wireless game controller for your PC.

This project creates a browser-based controller that connects your phone to your laptop over the local Wi-Fi/LAN and translates touch controls into real keyboard and mouse input.

No internet or cloud service is required.

โœจ Features

  • ๐ŸŽฎ Virtual joystick for W/A/S/D
  • ๐Ÿ–ฑ๏ธ Touch-based mouse/look control
  • โš”๏ธ Attack button โ†’ left mouse click
  • ๐Ÿ–๏ธ Use button โ†’ right mouse click
  • ๐Ÿฆ˜ Jump button โ†’ Space
  • ๐Ÿ”„ Vertical scroll wheel
  • โšก WebSocket-only communication for low latency
  • ๐Ÿ“ฑ Designed for mobile landscape mode
  • ๐ŸŽ›๏ธ Fully customizable controller layout
  • ๐Ÿ’พ Layout settings saved locally on the phone
  • ๐Ÿ”ง Adjustable look sensitivity
  • ๐Ÿ”Œ Automatically releases held keys when the phone disconnects
  • ๐ŸŒ Works entirely over your local network

๐Ÿ–ฅ๏ธ How It Works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚       ๐Ÿ“ฑ Phone     โ”‚
โ”‚                    โ”‚
โ”‚  ๐ŸŽฎ Touch Controls โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
          โ”‚
          โ”‚ WebSocket
          โ”‚ Local Wi-Fi
          โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚      ๐Ÿ’ป Laptop     โ”‚
โ”‚                    โ”‚
โ”‚  Node.js Server    โ”‚
โ”‚        โ†“           โ”‚
โ”‚      nut.js        โ”‚
โ”‚        โ†“           โ”‚
โ”‚  Keyboard / Mouse  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
          โ”‚
          โ–ผ
       ๐ŸŽฎ Game

The phone sends small control events to the Node.js server.

The server then converts those events into real operating-system keyboard and mouse inputs using @nut-tree-fork/nut-js.


๐Ÿ› ๏ธ Tech Stack

  • Node.js
  • Express
  • Socket.IO
  • @nut-tree-fork/nut-js
  • HTML
  • CSS
  • JavaScript

๐Ÿ“ Project Structure

phone-controller/
โ”‚
โ”œโ”€โ”€ public/
โ”‚   โ”œโ”€โ”€ index.html       # Controller interface
โ”‚   โ”œโ”€โ”€ style.css        # UI styling
โ”‚   โ””โ”€โ”€ app.js           # Touch controls & Socket.IO logic
โ”‚
โ”œโ”€โ”€ server.js            # Node.js server & OS input handling
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ package-lock.json
โ””โ”€โ”€ README.md

โš™๏ธ Requirements

  • Node.js 18 or newer
  • A laptop/PC
  • A smartphone
  • Both devices connected to the same Wi-Fi/LAN

Node.js 22+ is recommended.


๐Ÿš€ Installation

Clone the repository:

git clone https://github.com/not-rajharsh/phone-controller.git
cd phone-controller

Install dependencies:

npm install

โ–ถ๏ธ Start the Server

Run:

npm start

The server will display something similar to:

=== LAN Game Controller Server ===

Local:   http://localhost:3000
Network (Wi-Fi): http://192.168.1.42:3000

๐Ÿ“ฑ Connect Your Phone

  1. Connect your phone and laptop to the same Wi-Fi network.
  2. Start the server with npm start.
  3. Find the LAN address printed in the terminal.
  4. Open that address on your phone.

For example:

http://192.168.1.42:3000
  1. Rotate your phone into landscape mode.
  2. Open your game on the laptop.
  3. Make sure the game window has focus.
  4. Use your phone as the controller.

๐ŸŽฎ Controls

Phone Control PC Input
Joystick Up W
Joystick Left A
Joystick Down S
Joystick Right D
Jump Space
Attack Left Mouse Button
Use Right Mouse Button
Look Pad Mouse Movement
Scroll Wheel Mouse Wheel

๐ŸŽ›๏ธ Custom Layout

The controller includes an editing mode that allows you to:

  • Move controls
  • Resize controls
  • Change look sensitivity
  • Enable/disable the scroll wheel
  • Reset the layout

Your customized layout is stored in the phone's browser using:

localStorage

The layout is therefore preserved when you reopen the controller.


โšก Low-Latency Design

The project was designed specifically for responsive game controls.

WebSocket-only communication

Socket.IO is configured to use:

transports: ['websocket']

instead of starting with HTTP long-polling.

No unnecessary compression

Small controller packets don't benefit much from compression, so per-message compression is disabled.

Edge-triggered controls

Keyboard and mouse events are only sent when their state changes.

For example:

Touch joystick
      โ†“
Direction changes
      โ†“
key-down
      โ†“
W pressed

The application doesn't continuously spam W packets every frame.

Disconnect safety

If the phone disconnects while holding a button, the server releases the corresponding keyboard/mouse inputs.

This prevents situations where a game continues receiving a stuck key after the phone loses connection.


๐ŸŒ Improving Latency

For the best experience:

1. Use Ethernet for the laptop

Router โ”€โ”€โ”€ Ethernet โ”€โ”€โ”€ Laptop
   โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€ Wi-Fi โ”€โ”€โ”€โ”€โ”€ Phone

This reduces wireless jitter on the laptop side.

2. Use 5 GHz / 6 GHz Wi-Fi

Prefer 5 GHz or 6 GHz instead of 2.4 GHz when possible.

3. Stay close to the router

Distance and obstacles can increase packet loss and latency.

4. Avoid heavy network traffic

Pause large downloads, uploads, or streaming on the same network while playing.

5. Disable unnecessary Wi-Fi power saving

Power-saving features can sometimes introduce additional latency.


๐Ÿง  Interesting Implementation Details

Relative joystick

The joystick calculates direction based on where the user's thumb initially touches rather than requiring the thumb to land exactly in the center.

Joystick hysteresis

The controller uses different thresholds for engaging and releasing a direction.

This helps prevent rapid switching when the thumb is near a directional boundary.

Relative mouse movement

The look pad sends movement deltas rather than absolute cursor positions:

Swipe โ†’ ฮ”X, ฮ”Y
          โ†“
      Node.js
          โ†“
   Current cursor
          โ†“
   New cursor position

Scroll conversion

Vertical swipes are converted into discrete mouse-wheel events rather than continuous scrolling.


๐Ÿ”ง Customizing Controls

Keyboard mappings are defined in:

server.js

The main mapping is:

const KEY_MAP = {
  w: Key.W,
  a: Key.A,
  s: Key.S,
  d: Key.D,
  space: Key.Space,
};

You can modify this mapping to change the keyboard controls.

Button actions can be customized through:

public/index.html
public/app.js

๐Ÿ–ฅ๏ธ OS Support

Windows

Works without additional accessibility permissions.

macOS

Node.js may require Accessibility permission.

Go to:

System Settings
โ†’ Privacy & Security
โ†’ Accessibility

and allow the terminal/Node process.

Linux

The project currently requires an X11 environment for OS-level input simulation.


โš ๏ธ Troubleshooting

Phone cannot connect

Check:

  • Both devices are on the same network.
  • The server is running.
  • You're using the laptop's LAN IP rather than localhost.
  • Port 3000 isn't blocked by your firewall.

Example:

http://192.168.1.42:3000

Keyboard/mouse doesn't respond

Make sure:

  • The game window has focus.
  • The Node.js process has the required OS permissions.
  • npm install completed successfully.

npm install fails

On Windows, you may need:

  • Python
  • Visual Studio Build Tools
  • Desktop C++ workload

On Debian/Ubuntu:

sudo apt install build-essential libx11-dev libxtst-dev libpng-dev

๐Ÿ”ฎ Possible Future Improvements

Some ideas for future versions:

  • ๐ŸŽฎ Multiple controller profiles
  • ๐ŸŽฏ Game-specific layouts
  • ๐Ÿ“ก Connection/latency indicator
  • ๐Ÿ” Optional pairing/authentication
  • ๐ŸŽจ Custom themes
  • ๐ŸŽค Voice/chat controls
  • ๐Ÿ•น๏ธ Analog joystick support
  • ๐Ÿ“ฑ PWA installation
  • ๐Ÿ”„ Automatic device discovery
  • ๐Ÿ“Š Real-time latency statistics

๐Ÿ“„ License

Add your preferred license here.


๐Ÿ‘จโ€๐Ÿ’ป Author

Harsh Raj

Computer Science student interested in:

  • Cybersecurity
  • AI/ML
  • AI-assisted problem solving
  • Systems & networking
  • Building practical projects

GitHub:
https://github.com/not-rajharsh

About

Turn your phone into a wireless game controller for your PC.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages