GTK: check KeyEvent including switch key

In my application, I would like to check the GTK key_press event with a key combination <Ctrl><Shift><#>.
My code: (In this case, Python, but the problem is not language dependent, I think)

def on_key_press(self, widget, event):
    if ((event.keyval == Gdk.KEY_numbersign) \  # The problem
    and (event.state & Gdk.ModifierType.SHIFT_MASK) \
    and (event.state & Gdk.ModifierType.CONTROL_MASK)):

        dosomethingamazing()

The Gtk method handles keystrokes, the actual key (for example, "a") and the shift key are combined in upper case A. Thus, the keyign keys are replaced with the apostrophe key in the QWERTZ layout when the shift key is pressed. The .keyval event for this combination is 39 (apostrophe), not 35 (numberign). Thus, for <Ctrl><Shift><#>me, I need to check the uppercase equivalent of numberign, not numberign, which may differ on different keyboard layouts, so I can’t hardcode it.

The problem is this:

>>> Gdk.keyval_to_upper(35)  # 35 is the Key Value for numbersign
35
>>> Gdk.keyval_is_upper(35)
True
>>> Gdk.keyval_is_lower(35)
True

, . , <shift><whateverkey>, keyval_to_upper() ?

+4

All Articles