[Sugar-devel] tracking CTRL and ALT keys in a sugar activity

Michael Stone michael at laptop.org
Sat Dec 18 00:02:45 EST 2010


On Fri, Dec 17, 2010 at 4:48 PM, Erik Blankinship <erikb at mediamods.com> wrote:
> On Fri, Dec 17, 2010 at 4:52 PM, Walter Bender <walter.bender at gmail.com>wrote:
>> On Fri, Dec 17, 2010 at 4:48 PM, Erik Blankinship <erikb at mediamods.com> wrote:
>>> I would like to know when CTRL or ALT are being pressed in my sugar
>>> activity. To be complete, I would need to know if they are pressed when
>>> the activity regains focus (e.g. changing activities or if the focus was in
>>> a textfield).
>>>
>>> I am not sure of the right way to do this. My current thinking is to keep a
>>> dictionary with CTRL_L, CTRL_R, ALT_L, and ALT_R key states which are
>>> updated on key-press and key-release events.
>>>
>>> But this model breaks as soon the application loses focus and the user
>>> releases one of those keys -- I would never know when there is a mouse-up.
>>> My workaround is to clear the dictionary when the application loses focus. 
>>> I can also attempt to update the dictionary when there are mouse events by
>>> skimming information from these events regarding CTRL and ALT modifiers.
>>>
>>> Is this a good approach? Maybe I am missing something obvious?
>>
>> Maybe I am misunderstanding the complexity of what you are trying to
>> do...
>
> I want to change my cursor into a magicwand whenever CTRL or ALT are held
> down, and when none of them are pressed, I want to change my cursor into the
> system pointer.  I do not want someone to cheat by switching out of the
> activity with CTRL down and return with my activity thinking CTRL is still
> down.
>
>> don't you simply check the mode mask when you get a keyboard event to
>> determine whether or not Alt or Ctrl is pressed?
>
> Thank you!  Yes, I can do that while the activity is running.  That sure
> makes things simpler while the activity has focus.
> 
> But to determine if CTRL or ALT are pressed when returning to the activity?  
> 
> I am not sure what signal to listen to that would have the correct mode mask.

Erik,

I'm not sure how to get to these data from GTK and Python but I do know that
you want X's "KeymapNotify event" and "XQueryKeymap()" query:

   http://www.sbin.org/doc/Xlib/chapt_09.html

Perhaps with this hint, someone else on the list can help you further.

Regards,

Michael


More information about the Sugar-devel mailing list