Michal Suchanek
4/21/2007 6:20:00 PM
On 21/04/07, bjornms@gmail.com <bjornms@gmail.com> wrote:
> On Apr 21, 12:23 pm, "Michal Suchanek" <hramr...@centrum.cz> wrote:
> > On 19/04/07, bjor...@gmail.com <bjor...@gmail.com> wrote:
> >
> > > Hi
> >
> > > I'm trying to create a simple ruby script, which forks mplayer and
> > > afterwards it stays in a while loop which blocks on gets (this is to
> > > get keyboard input). I start this script from a terminal (linux). When
> > > i start it, it forks mplayer and the focus is on mplayer now. If i
> > > press some keys on my keyboard these are send to mplayer.
> >
> > > Is there a solution to get focus on the terminal/script again (without
> > > user interaction) after i started mplayer? Or another solution to get
> > > keyboard commands into my script?
> >
> > In X the newly started program usually gets keyboard focus unless you
> > configure your windowmanager do do something special. Of course, the
> > steps vary wildly between different windowmanagers, and may would
> > probably not allow such thing at all.
> >
> > However, if you started the script from another machine through ssh or
> > on another X server (you should be able to put in another videocard,
> > and start a second X server) you should get the input to your script.
>
> Is there a way to get all keyboard input with my ruby script.
>
I guess there is no portable way (across different X desktops) except
keyboard grab. However, keyboard grab is quite problematic. If your
script breaks and does not release the grab nothing in X (not even the
windowmanager) can use keyboard until you kill it. You will need some
Xlib bindings or X11 protocol library like RubyX11 for that (you need
to talk to the X server). And you will probably have to extend
whatever you use to support such exotic feature.
Using input grab (especially long) is considered quite unfriendly. It
looks like firefox uses input grab for DnD and likes to lock up with
input grabbed :-S
However, mplayer has some feature that allows you to specify a window
id into which the video is rendered (it is used for mplayer mozilla
plugin). That should avoid these problems. Have it render in the
terminal window or open a window of your own that does not receive
focus (I beleive there is a flag for that, and since it is your window
you can get the input anyway).
Thanks
Michal