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

Has anyone ever used SendKeycode from the X11::SendEvent mod and if so, can you show me how? Everything works flawlessly up to the last line...I believe
#!/usr/bin/perl -w use X11::SendEvent; $win = X11::SendEvent->new(win => ["Crystal Space Application"]); $win->SendKeycode(119);
At which time, I get the following:
Use of uninitialized value in string eq at /usr/lib/perl5/vendor_perl/ +5.8.8/X11/Protocol.pm line 535. Use of uninitialized value in string eq at /usr/lib/perl5/vendor_perl/ +5.8.8/X11/Protocol.pm line 536. Use of uninitialized value in string eq at /usr/lib/perl5/vendor_perl/ +5.8.8/X11/Protocol.pm line 536. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541. Use of uninitialized value in string eq at /usr/lib/perl5/vendor_perl/ +5.8.8/X11/Protocol.pm line 535. Use of uninitialized value in string eq at /usr/lib/perl5/vendor_perl/ +5.8.8/X11/Protocol.pm line 536. Use of uninitialized value in string eq at /usr/lib/perl5/vendor_perl/ +5.8.8/X11/Protocol.pm line 536. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541. Use of uninitialized value in pack at /usr/lib/perl5/vendor_perl/5.8.8 +/X11/Protocol.pm line 541.
It doesn't seem like this one gets a lot of use or talked about. I have a need to send keystrokes and not strings. X11:GUItest lets me send mouse events and strings all day long, but so far, this is the only thing that should(?) let me play with the keyboard. Thanks for any help you can offer
-Jasper

Replies are listed 'Best First'.
Re: SendKeyCode using X11::SendEvent
by zentara (Cardinal) on Dec 06, 2006 at 17:40 UTC
    Hi, I just tried it with "debug" and it seems to work with out error, but no strings are displayed in the window. I started an xterm with "xterm -title foo" , and ran the script
    #!/usr/bin/perl use warnings; use strict; use X11::SendEvent; $|++; my $win = X11::SendEvent->new( win => [ 'foo' ], debug => 1 ); $win->SendString( "testing", [ "Return" ] ); $win->SendString( "user", [ "Return" ], "joe", [ "9/1" ] ); $win->SendKeycode( 119 );
    and the debug out looked good
    zentara@:zentara$ ./send-event1 > X11::SendEvent - FindWin() > X11::SendEvent - - 41943053 [0x280000d]

    So I looked at xvkbd and followed their basic instructions. It worked, but I needed to use the "focus" button technique described in the man page. It has to do with the "focus follows mouse" setting of your Window Manager. So I believe that the problem is the window you are trying to send to, must take focus for the script to work. I havn't figured out how to send a WM control to programatically force focus on an arbitrary window, but I think that is what you need to do before sending the events.


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum