Thursday, March 30, 2006

Help: Remote control using hotkeys

When I am translating movies, I write the text on my PC (in OpenOffice), while I play the video on my laptop if MPlayer, using SPACE and arrow to pause, advance the video. Both computers have Ubuntu Linux installed on them.

When you translate the movie, you use pausing and skipping few seconds forward/backward very often. I'd like to make my life simpler. I want to control my laptop from my main computer in the following way: When translating the movie, my computer's OpenOffice would work as normal except that the computer would recognize three special keystrokes (for example Ctrl+Right, Ctrl+Left, Ctrl+Space) which would skip and pause the video on the second computer (the laptop) so that I wouldn't have to move my hands between two keyboards.

Controlling the MPlayer on laptop from the main computer is actually very easy. I can just open the SSH connection to laptop, start MPlayer there using "-slave" and then send ASCII commands to control it. Or I can use the MPlayer's remote control capabilities. Anyway, this part is easy. The problem I cannot easily solve is that the simple "control application" on my main computer (which I'd like to write in Ruby) has to somehow "grab" selected keyboard events even when it's not focused (because I am using the control keys while I am writing the translation in OpenOffice). I have do idea how this could be done in the simplest possible way (although I'm sure there are many ways to solve this).

Just to summarize: My problem is not with the video remote control itself. I just need some simple way my Ruby script can monitor the special keypresses without its window having to be active. So far I found out I can monitor "/dev/input/event0" and find the info there but this doesn't look very elegant and requires the script to have root privileges.

9 comments:

Anonymous said...

So you want control MPlayer when you are writing in OO.org, right? Easy solution is to write a macro in OO.org which will be launched by your keystroke. And the macro will be pretty simple, just starting your Ruby script.

František Fuka said...

Do you mean writing one OO Basic macro that does equivalent of "echo forwad > /tmp/playercommand", another one that does "echo pause > /tmp/playercommand" etc... and then having the remote control script read from this file?

Anonymous said...

I assume that you already have some script(s) with witch you can control MPlayer on your remote computer (pause_remote_mplayer_via _ssh.sh, stop_remote_mplayer_via_ssh.sh, etc.). (It's easy to write them, anyway) And you can run them from CLI on your local machine.
In this case use OO.org Basic macros just as a launcher for these scripts. You can assign a keyboard shortcut to them and there is a Shell() function in OO.org Basic for starting any application.
Or maybe you can write everything withinside OO.org Basic (but this is not my kind of language ;-))

Anonymous said...

There is more ways to do it, but one of them is to add a command to be run from the window manager. Most window manager support the "run a command when this key is pressed" functionality, and can handle the X11 key grabs for you.

-Yenya

Anonymous said...

I must be missing something here - why don't
you just play and write on the same machine,
switching workspaces in your windowmanager?

Anonymous said...

Maybe you could give a try.
It allows you to control two or more computers using just one mouse & keyboard and there is also some hotkeys functionality built in.

Anonymous said...

Seems my link was mysteriously broken. :(
The project mentioned above is called 'Synergy' and its homepage is at http://synergy2.sourceforge.net/

František Fuka said...

hans: That's what I've been doing until now! And it pisses me off to switch the workspaces/windows every 2 seconds and be unable to rewind the movie while watching the translation.

jtk: Thanks, I'll have look at it

Anonymous said...

If it was me, I'd bind the key-combinations to action in window manager (fluxbox does that really easily) or bind multimedia keys (using hotkeys).

Then it's just simple matter of using script of some sort.

You can even use ruby's "net/ssh" for that job and launch some small controlling daemon (also written in Ruby) on the second desktop.

Oh, and speaking of simple ... "drb" is good way to go about remote calls ;) and so is "webrick"-based interface ;)

Drop me a line should you need details and/or help.