In my application, I would like to check for a GTK key_press event with the key combination <Ctrl><Shift><#>
.
My code: (In this case, Python, but the problem is language-independent, I guess)
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 way Gtk handles keypresses, the actual key (for example "a") and the shift key are combined to an uppercase A. So numbersign keys get replaced by an apostrophe key on the QWERTZ layout when the shift key is pressed.
The event.keyval for this combination is 39 (apostrophe), not 35 (numbersign).
So, for <Ctrl><Shift><#>
I need to check for the uppercase equivalent of numbersign, instead of numbersign, which might be different on different keyboard layouts, so I cannot hard-code it.
The problem is the following:
>>> 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
I cannot get the uppercase equivalent using these functions. Any ideas on how to fetch the result of a <shift><whateverkey>
combination, where keyval_to_upper()
fails?