Changes

Line 272: Line 272:  
         elif (keyname == 'KP_End'):
 
         elif (keyname == 'KP_End'):
 
             self._chat += "\nCheck Pressed!"
 
             self._chat += "\nCheck Pressed!"
 +
            self._chat_buffer.set_text(self._chat)
 +
 +
        return False;
 +
</pre>
 +
 +
 +
=== How do I detect if one of the joystick buttons has been pressed? ===
 +
 +
This is the same process as detecting game buttons, except with different names for the keys. Again, you listen for "key-press-event" signals and then in your callback you check to see if the pressed button was one of the joystick keys.
 +
 +
<pre>
 +
    #### Initialize this activity.
 +
    def __init__(self, handle):
 +
        ...
 +
        self.connect('key-press-event', self._keyPressCb)
 +
        ...
 +
 +
    #### Method _keyPressCb, which catches any presses of the game buttons.
 +
    def _keyPressCb(self, widget, event):
 +
 +
        keyname = gtk.gdk.keyval_name(event.keyval)
 +
       
 +
        if (keyname == 'KP_Up'):
 +
            self._chat += "\nUp Pressed!"
 +
            self._chat_buffer.set_text(self._chat)
 +
        elif (keyname == 'KP_Down'):
 +
            self._chat += "\nDown Pressed!"
 +
            self._chat_buffer.set_text(self._chat)
 +
        elif (keyname == 'KP_Left'):
 +
            self._chat += "\nLeft Pressed!"
 +
            self._chat_buffer.set_text(self._chat)
 +
        elif (keyname == 'KP_Right'):
 +
            self._chat += "\nRight Pressed!"
 
             self._chat_buffer.set_text(self._chat)
 
             self._chat_buffer.set_text(self._chat)
  
Anonymous user