[pygtk] Re: problems with ctrl keybindings

Fabian Braennstroem f.braennstroem at gmx.de
Sun Mar 18 06:08:14 WST 2007


Hi Bryan,


Bryan Feir schrieb am 03/17/2007 08:07 PM:
> On Sat, Mar 17, 2007 at 06:47:38PM +0000, Fabian Braennstroem wrote:
>> Hi to both,
>>
>> Bryan Feir schrieb am 03/16/2007 02:34 PM:
>>>    Yes.  Specifically the problem is that if you use '==', then the
>>> match won't work if you have any other modifier keys active, including
>>> NumLock.  Which could be why it seemed to work before but not now.  So
>>> you need to check only those state bits that you require.  If you need
>>> to match Control but not Shift, for example, then it would be something
>>> like:
>>>  (event.state & (gtk.gdk.CONTROL_MASK|gtk.gdk.SHIFT_MASK)) ==
>>>    gtk.gdk.CONTROLMASK
>> thanks for your advice, but I did not tell you everything... I am
>> able to catch the 'control' key, but when I have an additional
>> binding just e.g. for 'l' like:
>>
>>         if keyname == "l":
>>
>> both bindings get 'activated', when pressing 'Ctrl+l'. Do you have
>> any idea to correct this?
> 
> Well, then you want to check that 'l' is pressed without CTRL instead:
> 
>   if keyname == "l" and
>     (event.state & gtk.gdk.CONTROL_MASK) == gtk.gdk.CONTROL_MASK:
> 		do_control_l()
>   if keyname == "l" and (event.state & gtk.gdk.CONTROL_MASK) == 0:
> 		do_l()

thanks, that was pretty easy!

Greetings!
Fabian



More information about the pygtk mailing list