Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Gtk2 X11 GrabKey

by Rhandom (Curate)
on Dec 14, 2013 at 22:11 UTC ( #1067184=note: print w/replies, xml ) Need Help??

in reply to Gtk2 X11 GrabKey

X11::Protocol often is just a simple network socket. You can access the deep underlying handle and wait for input via select - and it is pretty simple. I did that in File::KeePass::Agent in the module because I wanted to listen for global events as well as have a local gui running at the same time in the same process. Here is the relevant code snippet:

sub _listen { my $self = shift; my $x = $self->x; $x->event_handler('queue'); # listen to both the x protocol events as well as our local term require IO::Select; my $in_fh = ...; # some other handle I'm looking at my $x_fh = $x->{'connection'}->fh; $x_fh->autoflush(1); $in_fh->autoflush(1); my $sel = IO::Select->new($x_fh, $in_fh); # handle events as they occur $self->_init_state(1); my $i; while (1) { my ($fh) = $sel->can_read(10); next if ! $fh; if ($fh == $in_fh) { $self->_handle_term_input($fh) || last; } else { $self->read_x_event; } } } sub read_x_event { my $self = shift; my $cb_map = shift || $self->{'global_cb_map'} || die "No global c +allbacks initialized\n"; my $x = $self->x; my %event = $x->next_event; return if ($event{'name'} || '') ne 'KeyRelease'; my $code = $event{'detail'}; my $mod = $event{'state'}; ... the rest of my code here }

Once you have a select handle, you can can_read for input with a time out as part of the Gtk loop or any AnyEvent loop - but I'll leave that for you to setup :)

my @a=qw(random brilliant braindead); print $a[rand(@a)];

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067184]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2020-09-23 04:37 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (130 votes). Check out past polls.