Defining HotKeys in Angular 2 App

454 views
Skip to first unread message

Benin Yesu

unread,
May 16, 2016, 7:40:19 PM5/16/16
to AngularJS
Hello,

I am planning to migrate a Windows based thick client application to Angular 2. Current VB6 application users are used to use HotKeys (KeyBoard shortcuts). Being Angular 2 app will run in a browser, will I be able to use the hotkeys? I could find online the we can handle keypress event but what about reserved keys (such as. Ctrl + P), which browser interrupts in between user and App. Will I be able to change the default behavior of the browser for that key press and get the control in the app (bypassing browser)?

Thanks,
Jesu Benin.

Nicholas Richardson

unread,
Jun 16, 2016, 11:44:28 AM6/16/16
to AngularJS

You can use a library I created called angular2-hotkeys

It lets you create hotkeys like this:


constructor(private _hotkeysService: HotkeysService) {
   
this._hotkeysService.add(new Hotkey('meta+shift+g', (event: KeyboardEvent) => {
        console
.log('Typed hotkey');
       
return false; // Prevent bubbling
   
}));
}
Or even multiple hotkeys for the same callback like this:

this._hotkeysService.add(new Hotkey(['meta+shift+g', 'alt+shift+s'], (event: KeyboardEvent, combo: string) => {
    console
.log('Combo: ' + combo); // 'Combo: meta+shift+g' or 'Combo: alt+shift+s'
   
return false; // Prevent bubbling
}));

Reply all
Reply to author
Forward
0 new messages