You can use a callback for sensor events to be notified when a button is pressed. Is this what you are looking for?
Code:
def onSensorDown(e):
if e.object is tracker:
print 'Button',e.button,'down'
viz.callback(viz.SENSOR_DOWN_EVENT,onSensorDown)
def onSensorUp(e):
if e.object is tracker:
print 'Button',e.button,'up'
viz.callback(viz.SENSOR_UP_EVENT,onSensorUp)