behd has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I tought that it would have been very easy but I already googled for one hour and found nothing...

Is it possible to send keystrokes in linux (Xorg) using perl ?!?

ie. "CTRL + ALT + Right"

TIA !

Replies are listed 'Best First'.
Re: Sending keystrokes (linux) ?!?
by gellyfish (Monsignor) on Aug 09, 2006 at 16:08 UTC
Re: Sending keystrokes (linux) ?!?
by zentara (Cardinal) on Aug 09, 2006 at 16:10 UTC
    It's really a complex question, because in X, your window manager will be intercepting many keystrokes. I'm using ICEWM on linux, and CTRL+ALT+RIGHT will cause my virtual desktops to cycle thru. If that is what you are trying to accomplish, look at this pseudocode
    use X11::WMCtrl; foreach my $wrksp (0..9){ $wmctrl->switch($wrksp);

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Hey that's the point, I want my wm to intercept the keystrokes :)
      I use XGL/Compiz and it's the combination of keys to switch between the faces of the cube.

      In fact, I have an IBM T42 laptop with HDAPS, a perlscript allow to record knock and then can be set in listen mode.
      (see: http://www-128.ibm.com/developerworks/linux/library/l-knockage.html )

      The listen mode allow to execute command -> I would like to write a perl script as command (ie. "sendkey.pl left" would rotate my cube left).

      Well I'll try what you said but I doubt that it's working with any wm...

      Thanks both for your fast replies :)
        Hehe thanks for X11::Protocol, I didn't use it (was kinda low level, for the stupid thing that I wanted to do) but it pointed me to: X11::GUITest

        which have a ready made SendKeys :p