19

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.

Oli
  • 289,791
  • 117
  • 680
  • 835
  • I'm even lazier than you. Instead of configuring a IR remote (I even bought one!), I additionally bought a [trust wireless keyboard](http://www.trust.com/products/product.aspx?artnr=14909). – MadMike Oct 14 '13 at 13:50

2 Answers2

18

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.

steeldriver
  • 131,985
  • 21
  • 239
  • 326
  • I don't deny it works but it's a bit miserable if you're trying to type in a network location one key at a time. – Oli Oct 14 '13 at 14:06
  • 3
    You can use `xdotool type` to send complete strings as-typed - see my edit above. – steeldriver Oct 14 '13 at 14:55
12

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.

Oli
  • 289,791
  • 117
  • 680
  • 835
  • ``-nomouse`` doesn't seem to work anymore; for me under ubuntu 16.04 x2x only prints the usage info, no matter where I put that flag. – Philipp Ludwig Jun 29 '17 at 19:33
  • Note that with current systems `x2x` doesn't produce keyboard input on the remote side if you use it with regular `-X` forwarding, but if you use "trusted X11 forwarding" (i.e. `ssh -Y htpc x2x -to :0`) it works. (see https://github.com/dottedmag/x2x/issues/9) – rakslice Aug 03 '23 at 09:21