Receiving H Events
What Are H Events?
H events, so named as they are prefixed with the text H:, are a new way of interacting with the simulator as of MSFS. They are defined in cockpit panel ModelBehaviors, and only go in one direction: from the panel to Javascript/HTML code.
H events are not required to be defined ahead of time, similar to L vars, and can be named with any contiguous alphanumeric characters. Each cockpit panel in MSFS sends a number of cockpit specific H events that have no analogous key event, such as pressing individual buttons on an FMS computer.
These individual panel specific events can be received by Javascript instruments.
How To Receive H Events
Inside your main instrument class that extends BaseInstrument
, you must define the method onInteractionEvent()
in order to receive H events:
class MyInstrument extends BaseInstrument {
get templateID(): string {
return 'MyInstrument';
}
//Will be called by the VCockpit system when a H event is received
public onInteractionEvent(args: string[]): void {
const hEventName = args[0];
console.log(`Got a H Event named ${hEventName}!`);
}
}
The avionics framework also provides a convenient utility publisher class to publish H events to an EventBus
:
class MyInstrument extends BaseInstrument {
private readonly eventBus = new EventBus();
private readonly hEventPublisher = new HEventPublisher(this.eventBus);
get templateID(): string {
return 'MyInstrument';
}
public connectedCallback(): void {
super.connectedCallback();
this.hEventPublisher.startPublish();
}
public onInteractionEvent(args: string[]): void {
this.hEventPublisher.dispatchHEvent(args[0]);
}
}
//Later, in a component:
const subscriber = this.props.bus.getSubscriber<HEvent>();
subscriber.on('hEvent')
.handle(eventName => console.log(`Got a H Event named ${eventName}!`));