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!

In reply to Gtk2 X11 GrabKey by basiliscos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.