Sending keypresses to remote X session over SSH
So I'm sitting in our living room on an Ubuntu laptop working while also watching a TV that is controlled by an Ubuntu HTPC. I have an IR remote set up and can control everything I need to with it, 99% of the time.
However text input on a remote isn't very easy. I don't need to do it very often but when I do, it feels easier to walk 15 feet to plug in a USB keyboard and do it that way. However... I'm criminally and medically lazy and feel walking any distance isn't just unnecessary, it shows the robots they have won. No more I say!
I can SSH into the HTPC fine... Now, how do I send keypresses to that remote computer's X session?
I should mention that I know I could VNC but the TV is 1080p and the laptop is 720p so this introduces some scaling issues. On a technical level, I'd rather a solution that gave me a way to temporarily turn the laptop into a remote keyboard.
You should be able to do that using the xdotool
command, after specifying the appropriate X display e.g. to simulate a single 'down arrow' press in the currently active window
$ DISPLAY=:0 xdotool getactivewindow key Down
For entering literal text, you can use xdotool type <string>
e.g.
$ DISPLAY=:0 xdotool getactivewindow type 'your text here'
The xdotool
package should be available from the Universe repository.
Using x2x
and some X11 forwarding, I got this to work.
ssh -X htpc x2x -to :0
The only downside currently is I had to bum into a TTY to kill SSH to exit it. Still looking up how to quit when I'm done! Otherwise, it's quite a nice and simple (and shortcuttable) method for transferring input from one computer to another.
Edit: adding -nomouse
gave me the ability to close the forwarded x2x
window and I can unfocus it to quickly go back to other things without needing to shut the connection down.