[pygtk] Re: problems with ctrl keybindings

Bryan Feir jenora at sympatico.ca
Sun Mar 18 05:07:33 WST 2007


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()

---------------------------+---------------------------------------------------
Bryan Feir           VA3GBF|"Every man has somewhere in the back of his head
Home:jenora at sympatico.ca   | the wreck of a thing which he calls his
                           | education."              -- Stephen Leacock
---------------------------+---------------------------------------------------


More information about the pygtk mailing list