#------------------------------------------------------------------------------ # # SimConnect Tagged Data Request Sample # # Description: # After a flight has loaded, request the vertical speed and pitot # heat switch setting of the user aircraft, but only when the data # has changed #------------------------------------------------------------------------------ import prepar3d from prepar3d.event import DataEvent from prepar3d.util import LatLon import logging logging.basicConfig(level=logging.DEBUG) def pos_callback(data): lat_lon = LatLon.from_simconnect_data_latlonalt(data['STRUCT LATLONALT']) print('LatLon: %s' % lat_lon) if __name__ == '__main__': with prepar3d.connect('Data Request Sample') as connection: position_event = DataEvent(prepar3d.SimulationVariable('STRUCT LATLONALT'), callback=pos_callback) connection.subscribe(position_event) connection.listen()
import prepar3d from prepar3d.event import SystemEvent import logging class MySystemEvent(SystemEvent): def __init__(self): self.count = 0 super().__init__('1sec') def event(self, event, cbData): self.count += 1 print('Event occurred %d times' % self.count) if self.count >= 4: self.unsubscribe() if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) with prepar3d.connect('System Event Sample') as connection: connection.subscribe(MySystemEvent()) connection.listen(100)
#!/usr/bin/env python #------------------------------------------------------------------------------ # # SimConnect Input Sample # # Description: # Ctrl-Shift-U key combination sets the brakes #------------------------------------------------------------------------------ # NOTE: This was taken from http://www.prepar3d.com/SDKv2/LearningCenter/LearningCenter.php # As the description states this example should set the brakes when the key combination shift+ctrl+u is pressed. # Apparently this is not the way it works cause pressing the default brakes key triggers the InputEvent and the # key combination shift+ctrl+u does nothing at all! import prepar3d from prepar3d.event import InputEvent if __name__ == '__main__': with prepar3d.connect('Input Event Sample') as connection: brakes_event = InputEvent('ctrl+u', callback=lambda e, d: print('Brakes'), sim_event='parking_brakes') connection.subscribe(brakes_event) connection.listen()
#!/usr/bin/env python #------------------------------------------------------------------------------ # # SimConnect Input Sample # # Description: # Ctrl-Shift-U key combination sets the brakes #------------------------------------------------------------------------------ # NOTE: This was taken from http://www.prepar3d.com/SDKv2/LearningCenter/LearningCenter.php # As the description states this example should set the brakes when the key combination shift+ctrl+u is pressed. # Apparently this is not the way it works cause pressing the default brakes key triggers the InputEvent and the # key combination shift+ctrl+u does nothing at all! import prepar3d from prepar3d.event import InputEvent if __name__ == '__main__': with prepar3d.connect('Input Event Sample') as connection: brakes_event = InputEvent('ctrl+u', callback=lambda e,d: print('Brakes'), sim_event='parking_brakes') connection.subscribe(brakes_event) connection.listen()
#------------------------------------------------------------------------------ # # SimConnect Tagged Data Request Sample # # Description: # After a flight has loaded, request the vertical speed and pitot # heat switch setting of the user aircraft, but only when the data # has changed #------------------------------------------------------------------------------ import prepar3d from prepar3d.event import DataEvent from prepar3d.util import LatLon import logging logging.basicConfig(level=logging.DEBUG) def pos_callback(data): lat_lon = LatLon.from_simconnect_data_latlonalt(data['STRUCT LATLONALT']) print('LatLon: %s' % lat_lon) if __name__ == '__main__': with prepar3d.connect('Data Request Sample') as connection: position_event = DataEvent( prepar3d.SimulationVariable('STRUCT LATLONALT'), callback=pos_callback) connection.subscribe(position_event) connection.listen()