I'm looking for a way in Gtk/Python to have an app listen for keypresses and when some of the special keys are pressed, perform an action (recreate a menu with different labels, since it's an appindicator). I can't really find a way to do it though. If anyone is able to help, I'd be thankful.
Asked
Active
Viewed 368 times
0
-
Could you explain a little more when you say special keys? Do you mean like `Ctrl`, `Alt` etc? Do you want to detect them along with mouse clicks or only when pressed without any mouse clicks involved? – another.anon.coward Dec 05 '12 at 13:45
-
@another.anon.coward I mean more about num/caps/scrolllock and insert. I want them to be detected whenever they are pressed. – Dec 05 '12 at 17:29
1 Answers
1
You probably need to handle the "key-press-event" (and probably also "key-release-event") of GtkWidget. PyGtk knows about it.
It should be inside some "windowing" widget, so you may need to use GtkEventBox as a container.

Basile Starynkevitch
- 223,805
- 18
- 296
- 547
-
Thanks. If you've got a minute, would you mind putting a simple example for how would this be used? I tried doing something with on_key_press_event and on_key_press, but I've no idea how to get them to activate, since this isn't in a window. – Dec 05 '12 at 10:19
-
It should be some windowing widget. And giving a complete example will take me more than an hour, I don't have that much time to help you. – Basile Starynkevitch Dec 05 '12 at 10:58
-
Thanks, just pointing to that should be enough. Simply couldn't figure into what I should have put it. – Dec 05 '12 at 17:12