huan-kun
huan-kun

Reputation: 195

python-keybinder and right hotkey string

Python-keybinder is used to set global hotkeys in my program. GtkToggleButton widget is used to retrieve keybinding from user (key-press-event/key-release-event).

User presses togglebutton and presses some keys (Left Control + t, f.e.). Togglebutton`s event (key-press-event) returns "Control_L" and "t". Program saves this into string "t" and calls keybinder.bind("t", callback). User presses that hotkey and ... nothing happens. I found strange thing after some time of digging - keybinder understands "Control" (without _L/_R), "Alt" etc, and does not understand "Control_L", "Alt_L"... Documentation says next:

Text from python-keybinder documentation:

bind(...)
    bind (keystring, callback, user_data) -> bool

    Keystring should be in the format understood by
    gtk.accelerator_parse. An example is '<Ctrl>space'.

Text from gtk/gtkaccelgroup.c:

Text from gdk/gdkkeynames.c:

Ok, and at last text from gdk/gdkkeysyms.h:

205 #define GDK_KEY_Control_L 0xffe3
206 #define GDK_KEY_Control_R 0xffe4

How can I set and use keybinder without replacing "Control_L" to "Control", "Alt_L" to "Alt" and etc?

Upd: Linux, Python 2.4-2.7

Upd2: I want to see difference between "left control" and "right control" and use these keys as different buttons. How can I do this with gtk.accelerator_parse()? Is there a way?

Thnx.

Upvotes: 1

Views: 1628

Answers (2)

nemo
nemo

Reputation: 12718

Just to add an example to the accepted answer, here is the python code solved my problem:

>>> import gtk
>>> gtk.accelerator_name(ord(';'),gtk.gdk.MOD1_MASK)
'<Alt>semicolon'

The function documentation is at http://www.pygtk.org/pygtk2reference/class-gtkaccelgroup.html#function-gtk--accelerator-name

The modifier constants are at: http://www.pygtk.org/pygtk2reference/gdk-constants.html#gdk-modifier-constants.

Upvotes: 2

Phillip Wood
Phillip Wood

Reputation: 841

GTK offers GtkCellRendererAccel for setting keybindings, this might be easier as you wont have to worry about converting between the two key description formats.

Upvotes: 2

Related Questions