namespace Keyboard { export class Receiver { public enabled : boolean ; private readonly callbacks : { [ action ] : ( ) => void ; } ; constructor ( private readonly shortcuts ) { this . enabled = true ; this . callbacks = { } ; const key_handler_for = ( action ) => ( ) => this . dispatch_shortcut ( action ) ; for ( const key of Object . keys ( this . shortcuts ) ) { Mousetrap . bind ( key , key_handler_for ( this . shortcuts [ key ] ) ) ; } } on ( action , callback ) { this . callbacks [ action ] = callback ; } dispatch_shortcut ( action ) { if ( this . enabled && action in this . callbacks ) { this . callbacks [ action ] ( ) ; } } } }