Skip to content

Commit

Permalink
Fix #84: Add keyboard shortcuts.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkem committed Oct 28, 2018
1 parent 97fb445 commit ea78bad
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/rms/rms.page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnDestroy, OnInit } from '@angular/core';

import { NavParams, PopoverController } from 'ionic-angular';
import { NavParams, PopoverController, ViewController } from 'ionic-angular';

import { TranslateService } from '@ngx-translate/core';

Expand Down Expand Up @@ -52,6 +52,7 @@ const FIELDS = [{
@Component({
providers: [CONTROL_UNIT_PROVIDER],
templateUrl: 'rms.page.html',
host: {'(window:keydown)': 'onKeyDown($event)'}
})
export class RmsPage implements OnDestroy, OnInit {

Expand All @@ -75,8 +76,9 @@ export class RmsPage implements OnDestroy, OnInit {

private subscription: Subscription;

constructor(public cu: ControlUnit, private logger: Logger, private settings: Settings, private speech: Speech,
params: NavParams, private popover: PopoverController, private translate: TranslateService)
constructor(public cu: ControlUnit, private logger: Logger, private settings: Settings,
private speech: Speech, params: NavParams, private popover: PopoverController,
private translate: TranslateService, private view: ViewController)
{
this.options = params.data;

Expand Down Expand Up @@ -281,6 +283,23 @@ export class RmsPage implements OnDestroy, OnInit {
menu.present({ev: event});
}

onKeyDown(event: KeyboardEvent) {
if (this.view.isLast()) {
switch (event.code) {
// on Android, Escape closes the application by default
case 'Escape':
case 'Space':
this.cu.trigger(ControlUnitButton.PACE_CAR);
event.stopPropagation();
break;
case 'Enter':
this.cu.trigger(ControlUnitButton.START);
event.stopPropagation();
break;
}
}
}

// see https://github.com/ngx-translate/core/issues/330
private getTranslations(key: string, params?: Object) {
return this.translate.get(key, params).concat(
Expand Down

0 comments on commit ea78bad

Please sign in to comment.