PlayStation 4 has lots of awesome exclusive games, and now you can enjoy those masterpieces from your PC thanks to Remote Play. Although, it's way more comfortable to play games in PS4 Remote Play with keyboard and mouse. That's where reWASD can save your day!
First of all, you can use PS4 Remote Play without controller at all. You only need to create a PS4 Remote Play keyboard and mouse preset with the settings that fit you the most, Apply, and roll. We also have made the preset for you that can emulate PS4 controller for Remote Play, you can find it in PS4 Remote Play profile inside reWASD after installation. But it might need some adjustments for mouse sensitivity, so feel free to use or config as a base for your PS4 Remote Play keyboard and mouse layout.
Second of all, if you still want to use the controller, but don't have a PS4 gamepad near, you can launch emulate PS4 controller for Remote Play with any physical gamepad plugged in. That way PS4 Remote Play Xbox controller settings can be the way you want them to be!
Feel free to check out the PS4 Remote Play keyboard and mouse profiles we have here in reWASD Community.
Save Big on new & used TV, Video & Home Audio Remote Controls from top brands like Samsung, Lg, Amazon & more. Shop our extensive selection of products and best online deals. Free Shipping for many items! NOTE: These instructions use Windows screenshots for a keyboard. Macintosh will look slightly different, but the instructions are the same for keyboard or mouse. When you see the 'Restart the device' window, follow the on-screen instructions to turn your device off and then back on.
Recent versions of the Raspberry Pi support USB on-the-go (USB OTG), which allows them to impersonate USB devices such as keyboards, thumb drives, and microphones. To take advantage of this, I made an open-source web app that turns my Pi into a fake keyboard. I call it Key Mime Pi.
It simulates the function of wireless mouse, keyboard and touchpad, also provides a variety of specialty control panels, such as Media Remote, Application Switcher and Web Browsing Remote, which. A wide low-latency touch pad, native iPad keyboard, full-size computer keyboard with 88 keys or create your own. You can create keyboard layouts by yourself for your own needs. Clone existing layout or create it from scratch, add touch pad or buttons of any size to any position and assign keys or hotkeys to them.
This post demonstrates how Key Mime Pi works and how you can build one for yourself.
To begin, install Raspberry Pi OS lite (formerly known as Raspbian) on a microSD card.
Enable SSH access by placing a file called ssh
on the microSD’s boot partition, and insert the microSD card into your Pi device. If you’re connecting over wireless, you’ll also need to create a wpa_supplicant.conf
file on the boot partition.
Connect the USB cable to your Pi’s USB OTG port. On the Pi 4, this is the USB-C port. For the Pi Zero, it’s the Micro-USB port labeled “USB.”
Connect the other end of the USB cable to the computer that you want to connect to as a keyboard. USB 3.0 ports work better because they output more power, but all the USB 2.0 ports I tested worked fine as well.
Your Pi should draw power from the computer’s USB port and power up.
You have two options for installing Key Mime Pi. You can do it using plain old bash, which requires no external tools. Or, for a touch of class, install it via Ansible, my favorite open source configuration management tool.
From a bash shell, enter the following commands to connect to your Pi and configure it for USB device emulation:
Allow the Pi to reboot, then SSH in again and start the Key Mime Pi web server:
If you’re an Ansible user, you can use my Key Mime Pi Ansible role for better automation. The following commands install Key Mime Pi on your device as a systemd service:
After you run the install script, Key Mime Pi will be available at:
Its interface looks like this:
And like, magic, when you type into your browser, the keys will appear on the machine connected to the Pi.
The real magic here comes from Linux’s USB Human Interface Device (HID) gadget driver. It allows user-mode applications to interact with the operating system as if they were USB devices.
The key-mime-pi configuration script creates a file path at /dev/hidg0
. Any program can read or write to this path, and the OS translates the data to keyboard signals.
To mimic a keyboard, the Pi has to communicate with the OS according to the USB HID spec. At 97 pages of keycodes and tables, that document is a bit of a slog, but it turns out that the protocol for keyboards is dead simple.
Upon each keystroke, the keyboard sends an 8-byte message called a “report.”
Byte Index | Purpose |
---|---|
0 | Modifier keys (Ctrl, Alt, Shift) |
1 | Reserved for manufacturers |
2 | Key #1 |
3 | Key #2 |
4 | Key #3 |
5 | Key #4 |
6 | Key #5 |
7 | Key #6 |
Sending the keys for “Hi” looks like this:
In addition to signalling key presses, keyboards must also indicate key releases. An 8-byte block of zeroes indicates that no keys are active.
The above example sent one keystroke at a time, but HID reports have space for six keys. This means you can send up to six keystrokes in a single message as long as they’re distinct keys:
When you type into a browser window, JavaScript generates events for each keystroke. The website keycode.info provides an excellent demonstration of this functionality in action.
JavaScript key events include keycodes, but they’re distinct from HID keycodes. Fortunately, there’s a mostly 1:1 mapping between the two. To translate from JavaScript to HID, I created a lookup table like this:
The Key Mime Pi server listens for JavaScript keycode events from the browser, translates them into HID codes, then sends them to the Pi’s HID interface at /dev/hidg0
.
Here’s how it works from end to end:
/dev/hidg0
.In my tests, USB ports from computers produced enough electricity to power the Pi, but under-voltage warnings appeared frequently in the system log:
The Pi was correctly detecting that standard USB 2.0 and USB 3.0 ports provide insufficient power to meet the Pi’s requirements.
Raspberry Pi Model | Power requirements |
---|---|
Pi Zero W | 5 V / 1.2 A |
Pi 4 | 5 V / 3.0 A |
Standard USB ports come up short:
USB Port Type | Power output |
---|---|
USB 2.0 | 5 V / 0.5 A |
USB 3.0 | 5 V / 0.9 A |
I currently am still searching for a solution tot his problem. Here are some possible solutions I have not yet tested:
If Key Mime Pi fails to forward keystrokes to the target machine, the first step is to determine whether the USB gadget is working properly.
Try the following commands:
If everything is working, you should see the following output on the machine the Pi is connected to via USB:
When testing Key Mime Pi on the Pi Zero W, I ran into a case where writes to /dev/hidg0
hung indefinitely. I tried a different Micro-USB to USB-A cable, and the problem went away. I suspect that the first cable was either damaged or supported power only and not data. If you run into hanging writes to /dev/hidg0
, try a USB cable that supports data transfer (most USB cables do).
Remote typing is fun, but it’s a bit impractical. When you’re typing into a system, it generally helps to see the output too.
My next step is to capture HDMI output from the target computer and embed it in Key Mime Pi’s web interface. That way, I’ll be able to plug my Pi into a headless server and have a virtual console in the browser. It will essentially be a low-cost, hackable KVM over IP device.
I have a working prototype using ffplay and an HDMI extender, but I’m still working on a solution that puts everything in a single browser window with low latency.
I now have a working solution that both captures video output from a target device and allows you to send keystrokes, all within a browser window.
A detailed follow-up post is coming soon, but in the meantime, you can pre-order pre-configured KVM Pi kits that include everything you need to build your own KVM Pi:
Key Mime Pi’s code is fully open source under the permissive MIT license:
Subscribe to get my latest posts by email.
Thanks for signing up! Check your email to confirm your subscription.