<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div class="h5"><br>
</div></div>You can use key-press-event event<br>
<a href="http://library.gnome.org/devel/gtk/stable/GtkWidget.html#GtkWidget-key-press-event" target="_blank">http://library.gnome.org/devel/gtk/stable/GtkWidget.html#GtkWidget-key-press-event</a><br>
see event.state to check what modifier was pressed<br>
<a href="http://library.gnome.org/devel/gdk/stable/gdk-Event-Structures.html#GdkEventKey" target="_blank">http://library.gnome.org/devel/gdk/stable/gdk-Event-Structures.html#GdkEventKey</a><br>
<div class="im"><br></div></blockquote><div><br></div><div>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:</div>
<div><ul><li>If a child presses both CTRL keys and release just one, the activity does not know a CTRL key is still pressed.</li><li>Does not detect if CTRL is down when the activity starts.</li><li>Does not detect if CTRL is down when the activity resumes focus.</li>
</ul></div><div>Is there a more elegant way to accomplish the goal of always knowing when a CTRL key is pressed?</div><div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"> def on_mouse_move_cb( self, scene, event ):</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace" size="1"> if gtk.gdk.CONTROL_MASK & event.state:</font></div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"> self.set_default_cursor( "wand" )</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace" size="1"> else:</font></div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"> self.set_default_cursor( "point" )</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace" size="1"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"> def on_key_press_cb( self, scene, event ):</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace" size="1"> if gtk.gdk.CONTROL_MASK & event.state or event.keyval in (gtk.keysyms.Control_L, gtk.keysyms.Control_R):</font></div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"> self.set_default_cursor( "wand" )</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace" size="1"> else:</font></div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"> self.set_default_cursor( "point" )</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace" size="1"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"> return False</font></div><div>
<font class="Apple-style-span" face="'courier new', monospace" size="1"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"> def on_key_release_cb( self, scene, event ):</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace" size="1"> ctrl_mask = (gtk.gdk.CONTROL_MASK & event.state) == True</font></div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"> ctrl_key = event.keyval in (gtk.keysyms.Control_L, gtk.keysyms.Control_R)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace" size="1"> if not ctrl_mask and ctrl_key:</font></div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"> self.set_default_cursor( "point" )</font></div>
</div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace" size="1"> return False</font></div>
</div><br>