http://www.perlmonks.org?node_id=1067146

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

Hello! I need to show my Gtk2 application, when some "global" hotkey is been pressed. I tried to do that way, but it doesn't work:
#!/usr/bin/env perl use 5.12.0; use strict; use warnings; use AnyEvent; use Carp; use Devel::Comments; use Gtk2 -init; use X11::Protocol; use X11::Keyboard; my $window = Gtk2::Window->new ('toplevel'); my $button = Gtk2::Button->new ('Quit'); $button->signal_connect (clicked => sub { Gtk2->main_quit }); $window->add ($button); $window->show_all; my $x = X11::Protocol->new; my $k = X11::Keyboard->new($x); my $mask = $x->pack_event_mask('KeyPress'); $x->ChangeWindowAttributes($x->root, event_mask => $mask); $x->event_handler(sub { say "z"; }); my $seq = $x->GrabKey($k->KeysymToKeycode("z"), 'AnyModifier', $x->root, 1, 'Asynchronous', 'Asy +nchronous'); Gtk2->main;
I need to get the global key press asynchronously; when I fetch them directly/synchronously, than it works:
$x->event_handler ('queue'); my %event = $x->next_event;
The problem with the last piece of code, that it blocks all my GUI. The guys in Internet offered an solution to use separate pthread in such a blocking manner, but it's OK for C, and not OK for perl. Thanks a lot for any suggestions!