from comtypes.client import GetEvents, CreateObject class SensorListener: """Catch and print sensor events.""" def __init__(self, sensor): self.sensor = sensor def SensorInput(self, this, inval=None): print "Rot: ", print self.sensor.Rotation.X, print self.sensor.Rotation.Y, print self.sensor.Rotation.Z print "Trans: ", print self.sensor.Translation.X, print self.sensor.Translation.Y, print self.sensor.Translation.Z def PumpMessages(): from ctypes import windll, byref from ctypes.wintypes import MSG user32 = windll.user32 msg = MSG() PM_REMOVE = 0x0001 while user32.GetMessageA(byref(msg), 0, 0, 0): user32.TranslateMessage(byref(msg)) user32.DispatchMessageA(byref(msg)) def main(): # Get device device = CreateObject("TDxInput.Device") if device.Connect() == 0: print "3DConnexion Device Connected!" con = GetEvents(device.sensor, SensorListener(device.sensor)) try: PumpMessages() except KeyboardInterrupt: return if __name__ == "__main__": main()