Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found