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

Erik Blankinship erikb at mediamods.com
Mon Dec 20 09:28:50 EST 2010


>
>
> You can use key-press-event event
>
> http://library.gnome.org/devel/gtk/stable/GtkWidget.html#GtkWidget-key-press-event
> see event.state to check what modifier was pressed
>
> http://library.gnome.org/devel/gdk/stable/gdk-Event-Structures.html#GdkEventKey
>
>
Below is what I have assembled in an attempt to solve the problem of knowing
when CTRL is pressed in an activity from the moment it launches. It relies
on key-press, key-release, and mouse-move events. As is, it does not catch
these edge cases:

   - If a child presses both CTRL keys and release just one, the activity
   does not know a CTRL key is still pressed.
   - Does not detect if CTRL is down when the activity starts.
   - Does not detect if CTRL is down when the activity resumes focus.

Is there a more elegant way to accomplish the goal of always knowing when a
CTRL key is pressed?

    def on_mouse_move_cb( self, scene, event ):
        if gtk.gdk.CONTROL_MASK & event.state:
            self.set_default_cursor( "wand" )
        else:
            self.set_default_cursor( "point" )


    def on_key_press_cb( self, scene, event ):
        if gtk.gdk.CONTROL_MASK & event.state or event.keyval in
(gtk.keysyms.Control_L, gtk.keysyms.Control_R):
            self.set_default_cursor( "wand" )
        else:
            self.set_default_cursor( "point" )

        return False

    def on_key_release_cb( self, scene, event ):
        ctrl_mask = (gtk.gdk.CONTROL_MASK & event.state) == True
        ctrl_key = event.keyval in (gtk.keysyms.Control_L,
gtk.keysyms.Control_R)
        if not ctrl_mask and ctrl_key:
            self.set_default_cursor( "point" )

        return False
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20101220/a752b127/attachment.html>


More information about the Sugar-devel mailing list