Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Gtk2 X11 GrabKey

by dcmertens (Beadle)
on Dec 14, 2013 at 14:56 UTC ( #1067148=note: print w/ replies, xml ) Need Help??


in reply to Gtk2 X11 GrabKey

My initial reaction: why not just use the Gtk interface for detecting a key press? Isn't there a way to add an event callback for a keypress in Gtk? I know how to do this in Prima and can't imagine Gtk doesn't have something similar.

Then I re-read your post, and decided that when you said "I need to get the global key press asynchronously", that you want to get that keypress even if the user is actively using any application. Is that what you mean?


Comment on Re: Gtk2 X11 GrabKey
Re^2: Gtk2 X11 GrabKey
by Anonymous Monk on Dec 14, 2013 at 15:23 UTC

    ... using any application ...

    I think so, thats usually what they mean by "global hotkey" or "system wide hotkey"

    gtk apparently doesn't have a global hotkey capability built-in -- if the app/window doesn't have focus, it can't get events -- python/c/cpp folks apparently use libkeybinder (whatever that is)

    the OP issue appears to be that Gtk2->main; is blocking (or the other piece of code is blocking) ... so needs to poll, something along the lines of Re: AnyEvent + Wx, Gtk2/3 or Tk ?

      Thanks all!

      Unfortunately I don't see event-loop in X11::Protocol, i.e. polling capabilities. I don't wan't go to low-level capabilities, i.e. poll underlying socket for events. I'll try to use the libkeybinder, and tell the details here.

      PS. Mixed usage of Gtk2 events and X11 events seems to be leading to some messy:

      ... my $seq = $x->GrabKey( $k->KeysymToKeycode("z"), 'AnyModifier', $x->root, 0, 'Asynchronous', 'Asynchronous'); $x->event_handler('queue'); my %event = $x->next_event; ### %event my $t = AE::timer 0, 1, sub { my %event = $x->next_event; # %event }; Gtk2->main;
      It exists with:
      Protocol error: bad 2 (Value); Sequence Number 4 Opcode (33, 0) = GrabKey Bad value 183 (0xb7) at ./gtk-treeview-action line 31.

        Shouldn't you say something like return unless my %event = $x->dequeue_event rather than $x->next_event? The docs seem to suggest that next_event will block until you get your final results. As to your error, I'm not sure what to say as I don't use X11. Sorry.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-08-01 07:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (257 votes), past polls