feat: add save to keyboard and remap shortcut keys (#712)
* feat: add save to keyboard and remap shortcut keys * feat: Alt and Shift keys set the remapOnAllKeymap and remapOnAllLayer * fix: control + enter trigger remap keymap
This commit is contained in:
committed by
László Monda
parent
648e8d5f2c
commit
84f378a276
@@ -9,7 +9,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<notifier-container></notifier-container>
|
<notifier-container></notifier-container>
|
||||||
<progress-button class="save-to-keyboard-button"
|
<progress-button class="save-to-keyboard-button"
|
||||||
*ngIf="(saveToKeyboardState$ | async).showButton"
|
*ngIf="saveToKeyboardState.showButton"
|
||||||
[@showSaveToKeyboardButton]
|
[@showSaveToKeyboardButton]
|
||||||
[state]="saveToKeyboardState$ | async"
|
[state]="saveToKeyboardState"
|
||||||
(clicked)="clickedOnProgressButton($event)"></progress-button>
|
(clicked)="clickedOnProgressButton($event)"></progress-button>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Component, ViewEncapsulation } from '@angular/core';
|
import { Component, HostListener, ViewEncapsulation, OnDestroy } from '@angular/core';
|
||||||
import { animate, style, transition, trigger } from '@angular/animations';
|
import { animate, style, transition, trigger } from '@angular/animations';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { Subscription } from 'rxjs/Subscription';
|
||||||
import { Action, Store } from '@ngrx/store';
|
import { Action, Store } from '@ngrx/store';
|
||||||
|
|
||||||
import 'rxjs/add/operator/last';
|
import 'rxjs/add/operator/last';
|
||||||
@@ -34,17 +35,35 @@ import { ProgressButtonState } from './store/reducers/progress-button-state';
|
|||||||
])
|
])
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class MainAppComponent {
|
export class MainAppComponent implements OnDestroy {
|
||||||
showUpdateAvailable$: Observable<boolean>;
|
showUpdateAvailable$: Observable<boolean>;
|
||||||
deviceConfigurationLoaded$: Observable<boolean>;
|
deviceConfigurationLoaded$: Observable<boolean>;
|
||||||
runningInElectron$: Observable<boolean>;
|
runningInElectron$: Observable<boolean>;
|
||||||
saveToKeyboardState$: Observable<ProgressButtonState>;
|
saveToKeyboardState: ProgressButtonState;
|
||||||
|
|
||||||
|
private saveToKeyboardStateSubscription: Subscription;
|
||||||
|
|
||||||
constructor(private store: Store<AppState>) {
|
constructor(private store: Store<AppState>) {
|
||||||
this.showUpdateAvailable$ = store.select(getShowAppUpdateAvailable);
|
this.showUpdateAvailable$ = store.select(getShowAppUpdateAvailable);
|
||||||
this.deviceConfigurationLoaded$ = store.select(deviceConfigurationLoaded);
|
this.deviceConfigurationLoaded$ = store.select(deviceConfigurationLoaded);
|
||||||
this.runningInElectron$ = store.select(runningInElectron);
|
this.runningInElectron$ = store.select(runningInElectron);
|
||||||
this.saveToKeyboardState$ = store.select(saveToKeyboardState);
|
this.saveToKeyboardStateSubscription = store.select(saveToKeyboardState)
|
||||||
|
.subscribe(data => this.saveToKeyboardState = data);
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.saveToKeyboardStateSubscription.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
@HostListener('document:keydown', ['$event'])
|
||||||
|
onKeyDown(event: KeyboardEvent) {
|
||||||
|
if (this.saveToKeyboardState.showButton &&
|
||||||
|
event.ctrlKey &&
|
||||||
|
event.key === 's' &&
|
||||||
|
!event.defaultPrevented) {
|
||||||
|
this.clickedOnProgressButton(this.saveToKeyboardState.action);
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateApp() {
|
updateApp() {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
[keyboardLayout]="keyboardLayout"
|
[keyboardLayout]="keyboardLayout"
|
||||||
[description]="description"
|
[description]="description"
|
||||||
[showDescription]="true"
|
[showDescription]="true"
|
||||||
|
oncontextmenu="return false;"
|
||||||
(keyClick)="keyClick.emit($event)"
|
(keyClick)="keyClick.emit($event)"
|
||||||
(keyHover)="keyHover.emit($event)"
|
(keyHover)="keyHover.emit($event)"
|
||||||
(capture)="capture.emit($event)"
|
(capture)="capture.emit($event)"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 809 B After Width: | Height: | Size: 853 B |
@@ -3,6 +3,11 @@ import { animate, keyframes, state, style, transition, trigger } from '@angular/
|
|||||||
import { Layer } from 'uhk-common';
|
import { Layer } from 'uhk-common';
|
||||||
|
|
||||||
import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum';
|
import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum';
|
||||||
|
import {
|
||||||
|
SvgKeyboardCaptureEvent,
|
||||||
|
SvgKeyboardKeyClickEvent,
|
||||||
|
SvgKeyHoverEvent
|
||||||
|
} from '../../../models/svg-key-events';
|
||||||
|
|
||||||
type AnimationKeyboard =
|
type AnimationKeyboard =
|
||||||
'init' |
|
'init' |
|
||||||
@@ -82,9 +87,9 @@ export class KeyboardSliderComponent implements OnChanges {
|
|||||||
@Input() selectedKey: { layerId: number, moduleId: number, keyId: number };
|
@Input() selectedKey: { layerId: number, moduleId: number, keyId: number };
|
||||||
@Input() keyboardLayout = KeyboardLayout.ANSI;
|
@Input() keyboardLayout = KeyboardLayout.ANSI;
|
||||||
@Input() description: string;
|
@Input() description: string;
|
||||||
@Output() keyClick = new EventEmitter();
|
@Output() keyClick = new EventEmitter<SvgKeyboardKeyClickEvent>();
|
||||||
@Output() keyHover = new EventEmitter();
|
@Output() keyHover = new EventEmitter<SvgKeyHoverEvent>();
|
||||||
@Output() capture = new EventEmitter();
|
@Output() capture = new EventEmitter<SvgKeyboardCaptureEvent>();
|
||||||
@Output() descriptionChanged = new EventEmitter<string>();
|
@Output() descriptionChanged = new EventEmitter<string>();
|
||||||
|
|
||||||
layerAnimationState: AnimationKeyboard[];
|
layerAnimationState: AnimationKeyboard[];
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ export class PopoverComponent implements OnChanges {
|
|||||||
@Input() wrapPosition: any;
|
@Input() wrapPosition: any;
|
||||||
@Input() visible: boolean;
|
@Input() visible: boolean;
|
||||||
@Input() allowLayerDoubleTap: boolean;
|
@Input() allowLayerDoubleTap: boolean;
|
||||||
|
@Input() remapOnAllKeymap: boolean;
|
||||||
|
@Input() remapOnAllLayer: boolean;
|
||||||
|
|
||||||
@Output() cancel = new EventEmitter<any>();
|
@Output() cancel = new EventEmitter<any>();
|
||||||
@Output() remap = new EventEmitter<KeyActionRemap>();
|
@Output() remap = new EventEmitter<KeyActionRemap>();
|
||||||
@@ -101,9 +103,6 @@ export class PopoverComponent implements OnChanges {
|
|||||||
leftPosition: number = 0;
|
leftPosition: number = 0;
|
||||||
animationState: string;
|
animationState: string;
|
||||||
|
|
||||||
remapOnAllKeymap: boolean;
|
|
||||||
remapOnAllLayer: boolean;
|
|
||||||
|
|
||||||
private readonly currentKeymap$ = new BehaviorSubject<Keymap>(undefined);
|
private readonly currentKeymap$ = new BehaviorSubject<Keymap>(undefined);
|
||||||
|
|
||||||
constructor(store: Store<AppState>) {
|
constructor(store: Store<AppState>) {
|
||||||
@@ -143,8 +142,6 @@ export class PopoverComponent implements OnChanges {
|
|||||||
if (change['visible']) {
|
if (change['visible']) {
|
||||||
if (change['visible'].currentValue) {
|
if (change['visible'].currentValue) {
|
||||||
this.animationState = 'opened';
|
this.animationState = 'opened';
|
||||||
this.remapOnAllKeymap = false;
|
|
||||||
this.remapOnAllLayer = false;
|
|
||||||
} else {
|
} else {
|
||||||
this.animationState = 'closed';
|
this.animationState = 'closed';
|
||||||
}
|
}
|
||||||
@@ -179,6 +176,14 @@ export class PopoverComponent implements OnChanges {
|
|||||||
this.cancel.emit();
|
this.cancel.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HostListener('document:keydown.control.enter', ['$event'])
|
||||||
|
onKeyDown(event: KeyboardEvent) {
|
||||||
|
if (this.visible) {
|
||||||
|
this.onRemapKey();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
selectTab(tab: TabName): void {
|
selectTab(tab: TabName): void {
|
||||||
this.activeTab = tab;
|
this.activeTab = tab;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
[selectedKey]="selectedKey"
|
[selectedKey]="selectedKey"
|
||||||
[@split]="moduleAnimationStates[i]"
|
[@split]="moduleAnimationStates[i]"
|
||||||
[selected]="selectedKey?.moduleId === i"
|
[selected]="selectedKey?.moduleId === i"
|
||||||
(keyClick)="onKeyClick(i, $event.index, $event.keyTarget)"
|
(keyClick)="onKeyClick(i, $event)"
|
||||||
(keyHover)="onKeyHover($event.index, $event.event, $event.over, i)"
|
(keyHover)="onKeyHover($event.index, $event.event, $event.over, i)"
|
||||||
(capture)="onCapture(i, $event.index, $event.captured)" />
|
(capture)="onCapture(i, $event)" />
|
||||||
|
|
||||||
<svg:path [@fadeSeparator]="separatorAnimation"
|
<svg:path [@fadeSeparator]="separatorAnimation"
|
||||||
[attr.d]="separator.d"
|
[attr.d]="separator.d"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@@ -7,6 +7,12 @@ import { SvgModule } from '../module';
|
|||||||
import { SvgModuleProviderService } from '../../../services/svg-module-provider.service';
|
import { SvgModuleProviderService } from '../../../services/svg-module-provider.service';
|
||||||
import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum';
|
import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum';
|
||||||
import { SvgSeparator } from '../separator';
|
import { SvgSeparator } from '../separator';
|
||||||
|
import {
|
||||||
|
SvgKeyHoverEvent,
|
||||||
|
SvgKeyboardKeyClickEvent,
|
||||||
|
SvgKeyboardCaptureEvent,
|
||||||
|
SvgModuleKeyClickEvent
|
||||||
|
} from '../../../models/svg-key-events';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'svg-keyboard',
|
selector: 'svg-keyboard',
|
||||||
@@ -45,9 +51,9 @@ export class SvgKeyboardComponent implements OnInit {
|
|||||||
@Input() keyboardLayout = KeyboardLayout.ANSI;
|
@Input() keyboardLayout = KeyboardLayout.ANSI;
|
||||||
@Input() description: string;
|
@Input() description: string;
|
||||||
@Input() showDescription = false;
|
@Input() showDescription = false;
|
||||||
@Output() keyClick = new EventEmitter();
|
@Output() keyClick = new EventEmitter<SvgKeyboardKeyClickEvent>();
|
||||||
@Output() keyHover = new EventEmitter();
|
@Output() keyHover = new EventEmitter<SvgKeyHoverEvent>();
|
||||||
@Output() capture = new EventEmitter();
|
@Output() capture = new EventEmitter<SvgKeyboardCaptureEvent>();
|
||||||
@Output() descriptionChanged = new EventEmitter<string>();
|
@Output() descriptionChanged = new EventEmitter<string>();
|
||||||
|
|
||||||
modules: SvgModule[];
|
modules: SvgModule[];
|
||||||
@@ -79,19 +85,17 @@ export class SvgKeyboardComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyClick(moduleId: number, keyId: number, keyTarget: HTMLElement): void {
|
onKeyClick(moduleId: number, event: SvgModuleKeyClickEvent): void {
|
||||||
this.keyClick.emit({
|
this.keyClick.emit({
|
||||||
moduleId,
|
...event,
|
||||||
keyId,
|
moduleId
|
||||||
keyTarget
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onCapture(moduleId: number, keyId: number, captured: { code: number, left: boolean[], right: boolean[] }): void {
|
onCapture(moduleId: number, event: SvgKeyboardCaptureEvent): void {
|
||||||
this.capture.emit({
|
this.capture.emit({
|
||||||
moduleId,
|
...event,
|
||||||
keyId,
|
moduleId
|
||||||
captured
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+60
-14
@@ -26,6 +26,7 @@ import { MapperService } from '../../../../services/mapper.service';
|
|||||||
|
|
||||||
import { AppState } from '../../../../store';
|
import { AppState } from '../../../../store';
|
||||||
import { getMacros } from '../../../../store/reducers/user-configuration';
|
import { getMacros } from '../../../../store/reducers/user-configuration';
|
||||||
|
import { SvgKeyCaptureEvent, SvgKeyClickEvent } from '../../../../models/svg-key-events';
|
||||||
|
|
||||||
enum LabelTypes {
|
enum LabelTypes {
|
||||||
KeystrokeKey,
|
KeystrokeKey,
|
||||||
@@ -82,8 +83,8 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
@Input() capturingEnabled: boolean;
|
@Input() capturingEnabled: boolean;
|
||||||
@Input() active: boolean;
|
@Input() active: boolean;
|
||||||
|
|
||||||
@Output() keyClick = new EventEmitter();
|
@Output() keyClick = new EventEmitter<SvgKeyClickEvent>();
|
||||||
@Output() capture = new EventEmitter();
|
@Output() capture = new EventEmitter<SvgKeyCaptureEvent>();
|
||||||
|
|
||||||
enumLabelTypes = LabelTypes;
|
enumLabelTypes = LabelTypes;
|
||||||
|
|
||||||
@@ -96,6 +97,10 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
macros: Macro[];
|
macros: Macro[];
|
||||||
private subscription: Subscription;
|
private subscription: Subscription;
|
||||||
private scanCodePressed: boolean;
|
private scanCodePressed: boolean;
|
||||||
|
private pressedShiftLocation = -1;
|
||||||
|
private pressedAltLocation = -1;
|
||||||
|
private altPressed = false;
|
||||||
|
private shitPressed = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private mapper: MapperService,
|
private mapper: MapperService,
|
||||||
@@ -115,12 +120,16 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
@HostListener('click')
|
@HostListener('click')
|
||||||
onClick() {
|
onClick() {
|
||||||
this.reset();
|
this.reset();
|
||||||
this.keyClick.emit(this.element.nativeElement);
|
this.keyClick.emit({
|
||||||
|
keyTarget: this.element.nativeElement,
|
||||||
|
shiftPressed: this.pressedShiftLocation > -1,
|
||||||
|
altPressed: this.pressedAltLocation > -1
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('mousedown', ['$event'])
|
@HostListener('mousedown', ['$event'])
|
||||||
onMouseDown(e: MouseEvent) {
|
onMouseDown(e: MouseEvent) {
|
||||||
if ((e.which === 2 || e.button === 1) && this.capturingEnabled) {
|
if ((e.which === 2 || e.button === 2) && this.capturingEnabled) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.renderer.invokeElementMethod(this.element.nativeElement, 'focus');
|
this.renderer.invokeElementMethod(this.element.nativeElement, 'focus');
|
||||||
|
|
||||||
@@ -129,13 +138,29 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
} else {
|
} else {
|
||||||
this.recording = true;
|
this.recording = true;
|
||||||
this.recordAnimation = 'active';
|
this.recordAnimation = 'active';
|
||||||
|
|
||||||
|
if (this.pressedShiftLocation > -1) {
|
||||||
|
this.shitPressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.pressedAltLocation > -1) {
|
||||||
|
this.altPressed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('keyup', ['$event'])
|
@HostListener('document:keyup', ['$event'])
|
||||||
onKeyUp(e: KeyboardEvent) {
|
onKeyUp(e: KeyboardEvent) {
|
||||||
if (this.scanCodePressed) {
|
if (e.keyCode === 18 && this.pressedAltLocation > -1) {
|
||||||
|
this.pressedAltLocation = -1;
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
else if (e.keyCode === 16 && this.pressedShiftLocation > -1) {
|
||||||
|
this.pressedShiftLocation = -1;
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
else if (this.scanCodePressed) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.scanCodePressed = false;
|
this.scanCodePressed = false;
|
||||||
} else if (this.recording) {
|
} else if (this.recording) {
|
||||||
@@ -144,7 +169,7 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('keydown', ['$event'])
|
@HostListener('document:keydown', ['$event'])
|
||||||
onKeyDown(e: KeyboardEvent) {
|
onKeyDown(e: KeyboardEvent) {
|
||||||
const code: number = e.keyCode;
|
const code: number = e.keyCode;
|
||||||
|
|
||||||
@@ -152,11 +177,29 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (this.captureService.hasMap(code)) {
|
if (this.captureService.hasMap(code)) {
|
||||||
|
// If the Alt or Shift key not released after start the capturing
|
||||||
|
// then add them as a modifier
|
||||||
|
if (this.pressedShiftLocation > -1) {
|
||||||
|
this.captureService.setModifier((this.pressedShiftLocation === 1), 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.pressedAltLocation > -1) {
|
||||||
|
this.captureService.setModifier((this.pressedAltLocation === 1), 18);
|
||||||
|
}
|
||||||
|
|
||||||
this.saveScanCode(this.captureService.getMap(code));
|
this.saveScanCode(this.captureService.getMap(code));
|
||||||
this.scanCodePressed = true;
|
this.scanCodePressed = true;
|
||||||
} else {
|
} else {
|
||||||
this.captureService.setModifier((e.location === 1), code);
|
this.captureService.setModifier((e.location === 1), code);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (e.keyCode === 16) {
|
||||||
|
this.pressedShiftLocation = e.location;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.keyCode === 18) {
|
||||||
|
this.pressedAltLocation = e.location;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,22 +241,25 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
this.recording = false;
|
this.recording = false;
|
||||||
this.changeAnimation = 'inactive';
|
this.changeAnimation = 'inactive';
|
||||||
this.captureService.initModifiers();
|
this.captureService.initModifiers();
|
||||||
|
this.shitPressed = false;
|
||||||
|
this.altPressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private saveScanCode(code = 0) {
|
private saveScanCode(code = 0) {
|
||||||
this.recording = false;
|
|
||||||
this.changeAnimation = 'inactive';
|
|
||||||
|
|
||||||
const left: boolean[] = this.captureService.getModifiers(true);
|
const left: boolean[] = this.captureService.getModifiers(true);
|
||||||
const right: boolean[] = this.captureService.getModifiers(false);
|
const right: boolean[] = this.captureService.getModifiers(false);
|
||||||
|
|
||||||
this.capture.emit({
|
this.capture.emit({
|
||||||
code,
|
captured: {
|
||||||
left,
|
code,
|
||||||
right
|
left,
|
||||||
|
right
|
||||||
|
},
|
||||||
|
shiftPressed: this.shitPressed,
|
||||||
|
altPressed: this.altPressed
|
||||||
});
|
});
|
||||||
|
|
||||||
this.captureService.initModifiers();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private setLabels(): void {
|
private setLabels(): void {
|
||||||
|
|||||||
@@ -2,6 +2,12 @@ import { Component, EventEmitter, Input, Output, ChangeDetectionStrategy } from
|
|||||||
import { KeyAction } from 'uhk-common';
|
import { KeyAction } from 'uhk-common';
|
||||||
|
|
||||||
import { SvgKeyboardKey } from '../keys';
|
import { SvgKeyboardKey } from '../keys';
|
||||||
|
import {
|
||||||
|
SvgKeyCaptureEvent,
|
||||||
|
SvgKeyClickEvent,
|
||||||
|
SvgModuleCaptureEvent,
|
||||||
|
SvgModuleKeyClickEvent
|
||||||
|
} from '../../../models/svg-key-events';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'g[svg-module]',
|
selector: 'g[svg-module]',
|
||||||
@@ -17,18 +23,18 @@ export class SvgModuleComponent {
|
|||||||
@Input() selected: boolean;
|
@Input() selected: boolean;
|
||||||
@Input() keybindAnimationEnabled: boolean;
|
@Input() keybindAnimationEnabled: boolean;
|
||||||
@Input() capturingEnabled: boolean;
|
@Input() capturingEnabled: boolean;
|
||||||
@Output() keyClick = new EventEmitter();
|
@Output() keyClick = new EventEmitter<SvgModuleKeyClickEvent>();
|
||||||
@Output() keyHover = new EventEmitter();
|
@Output() keyHover = new EventEmitter();
|
||||||
@Output() capture = new EventEmitter();
|
@Output() capture = new EventEmitter<SvgModuleCaptureEvent>();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.keyboardKeys = [];
|
this.keyboardKeys = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyClick(index: number, keyTarget: HTMLElement): void {
|
onKeyClick(keyId: number, event: SvgKeyClickEvent): void {
|
||||||
this.keyClick.emit({
|
this.keyClick.emit({
|
||||||
index,
|
...event,
|
||||||
keyTarget
|
keyId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,10 +46,10 @@ export class SvgModuleComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onCapture(index: number, captured: {code: number, left: boolean[], right: boolean[]}) {
|
onCapture(keyId: number, event: SvgKeyCaptureEvent) {
|
||||||
this.capture.emit({
|
this.capture.emit({
|
||||||
index,
|
...event,
|
||||||
captured
|
keyId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
[halvesSplit]="halvesSplit"
|
[halvesSplit]="halvesSplit"
|
||||||
[keyboardLayout]="keyboardLayout"
|
[keyboardLayout]="keyboardLayout"
|
||||||
[description]="keymap.description"
|
[description]="keymap.description"
|
||||||
(keyClick)="onKeyClick($event.moduleId, $event.keyId, $event.keyTarget)"
|
(keyClick)="onKeyClick($event)"
|
||||||
(keyHover)="onKeyHover($event.moduleId, $event.event, $event.over, $event.keyId)"
|
(keyHover)="onKeyHover($event)"
|
||||||
(capture)="onCapture($event.moduleId, $event.keyId, $event.captured)"
|
(capture)="onCapture($event)"
|
||||||
(descriptionChanged)="onDescriptionChanged($event)"
|
(descriptionChanged)="onDescriptionChanged($event)"
|
||||||
></keyboard-slider>
|
></keyboard-slider>
|
||||||
|
|
||||||
@@ -22,6 +22,8 @@
|
|||||||
[currentKeymap]="keymap"
|
[currentKeymap]="keymap"
|
||||||
[currentLayer]="currentLayer"
|
[currentLayer]="currentLayer"
|
||||||
[allowLayerDoubleTap]="allowLayerDoubleTap"
|
[allowLayerDoubleTap]="allowLayerDoubleTap"
|
||||||
|
[remapOnAllKeymap]="remapOnAllKeymap"
|
||||||
|
[remapOnAllLayer]="remapOnAllLayer"
|
||||||
(cancel)="hidePopover()"
|
(cancel)="hidePopover()"
|
||||||
(remap)="onRemap($event)"></popover>
|
(remap)="onRemap($event)"></popover>
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ import { PopoverComponent } from '../../popover';
|
|||||||
import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum';
|
import { KeyboardLayout } from '../../../keyboard/keyboard-layout.enum';
|
||||||
import { ChangeKeymapDescription } from '../../../models/ChangeKeymapDescription';
|
import { ChangeKeymapDescription } from '../../../models/ChangeKeymapDescription';
|
||||||
import { KeyActionRemap } from '../../../models/key-action-remap';
|
import { KeyActionRemap } from '../../../models/key-action-remap';
|
||||||
|
import {
|
||||||
|
SvgKeyboardCaptureEvent,
|
||||||
|
SvgKeyboardKeyClickEvent,
|
||||||
|
SvgKeyHoverEvent
|
||||||
|
} from '../../../models/svg-key-events';
|
||||||
|
|
||||||
interface NameValuePair {
|
interface NameValuePair {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -65,7 +70,7 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
|
|||||||
|
|
||||||
@Output() descriptionChanged = new EventEmitter<ChangeKeymapDescription>();
|
@Output() descriptionChanged = new EventEmitter<ChangeKeymapDescription>();
|
||||||
|
|
||||||
@ViewChild(PopoverComponent, { read: ElementRef }) popover: ElementRef;
|
@ViewChild(PopoverComponent, {read: ElementRef}) popover: ElementRef;
|
||||||
|
|
||||||
popoverShown: boolean;
|
popoverShown: boolean;
|
||||||
keyEditConfig: { moduleId: number, keyId: number };
|
keyEditConfig: { moduleId: number, keyId: number };
|
||||||
@@ -82,6 +87,9 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
|
|||||||
layers: Layer[];
|
layers: Layer[];
|
||||||
keyPosition: ClientRect;
|
keyPosition: ClientRect;
|
||||||
wrapPosition: ClientRect;
|
wrapPosition: ClientRect;
|
||||||
|
remapOnAllKeymap: boolean;
|
||||||
|
remapOnAllLayer: boolean;
|
||||||
|
|
||||||
private wrapHost: HTMLElement;
|
private wrapHost: HTMLElement;
|
||||||
private keyElement: HTMLElement;
|
private keyElement: HTMLElement;
|
||||||
|
|
||||||
@@ -139,36 +147,38 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyClick(moduleId: number, keyId: number, keyTarget: HTMLElement): void {
|
onKeyClick(event: SvgKeyboardKeyClickEvent): void {
|
||||||
if (!this.popoverShown && this.popoverEnabled) {
|
if (!this.popoverShown && this.popoverEnabled) {
|
||||||
this.keyEditConfig = {
|
this.keyEditConfig = {
|
||||||
moduleId,
|
moduleId: event.moduleId,
|
||||||
keyId
|
keyId: event.keyId
|
||||||
};
|
};
|
||||||
this.selectedKey = { layerId: this.currentLayer, moduleId, keyId };
|
this.selectedKey = {layerId: this.currentLayer, moduleId: event.moduleId, keyId: event.keyId};
|
||||||
const keyActionToEdit: KeyAction = this.layers[this.currentLayer].modules[moduleId].keyActions[keyId];
|
const keyActionToEdit: KeyAction = this.layers[this.currentLayer].modules[event.moduleId].keyActions[event.keyId];
|
||||||
this.keyElement = keyTarget;
|
this.keyElement = event.keyTarget;
|
||||||
|
this.remapOnAllKeymap = event.shiftPressed;
|
||||||
|
this.remapOnAllLayer = event.altPressed;
|
||||||
this.showPopover(keyActionToEdit);
|
this.showPopover(keyActionToEdit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyHover(moduleId: number, event: MouseEvent, over: boolean, keyId: number): void {
|
onKeyHover(event: SvgKeyHoverEvent): void {
|
||||||
if (this.tooltipEnabled) {
|
if (this.tooltipEnabled) {
|
||||||
const keyActionToEdit: KeyAction = this.layers[this.currentLayer].modules[moduleId].keyActions[keyId];
|
const keyActionToEdit: KeyAction = this.layers[this.currentLayer].modules[event.moduleId].keyActions[event.keyId];
|
||||||
|
|
||||||
if (over) {
|
if (event.over) {
|
||||||
this.showTooltip(keyActionToEdit, event);
|
this.showTooltip(keyActionToEdit, event.event);
|
||||||
} else {
|
} else {
|
||||||
this.hideTooltip();
|
this.hideTooltip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onCapture(moduleId: number, keyId: number, captured: { code: number, left: boolean[], right: boolean[] }): void {
|
onCapture(event: SvgKeyboardCaptureEvent): void {
|
||||||
const keystrokeAction: KeystrokeAction = new KeystrokeAction();
|
const keystrokeAction: KeystrokeAction = new KeystrokeAction();
|
||||||
const modifiers = captured.left.concat(captured.right).map(x => x ? 1 : 0);
|
const modifiers = event.captured.left.concat(event.captured.right).map(x => x ? 1 : 0);
|
||||||
|
|
||||||
keystrokeAction.scancode = captured.code;
|
keystrokeAction.scancode = event.captured.code;
|
||||||
keystrokeAction.modifierMask = 0;
|
keystrokeAction.modifierMask = 0;
|
||||||
|
|
||||||
for (let i = 0; i < modifiers.length; ++i) {
|
for (let i = 0; i < modifiers.length; ++i) {
|
||||||
@@ -179,11 +189,11 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
|
|||||||
KeymapActions.saveKey(
|
KeymapActions.saveKey(
|
||||||
this.keymap,
|
this.keymap,
|
||||||
this.currentLayer,
|
this.currentLayer,
|
||||||
moduleId,
|
event.moduleId,
|
||||||
keyId,
|
event.keyId,
|
||||||
{
|
{
|
||||||
remapOnAllKeymap: false,
|
remapOnAllKeymap: event.shiftPressed,
|
||||||
remapOnAllLayer: false,
|
remapOnAllLayer: event.altPressed,
|
||||||
action: keystrokeAction
|
action: keystrokeAction
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
export interface SvgKeyClickEvent {
|
||||||
|
keyTarget: HTMLElement;
|
||||||
|
shiftPressed?: boolean;
|
||||||
|
altPressed?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SvgModuleKeyClickEvent extends SvgKeyClickEvent {
|
||||||
|
keyId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SvgKeyboardKeyClickEvent extends SvgModuleKeyClickEvent {
|
||||||
|
moduleId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface KeyCaptureData {
|
||||||
|
code: number;
|
||||||
|
left: boolean[];
|
||||||
|
right: boolean[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SvgKeyCaptureEvent {
|
||||||
|
captured: KeyCaptureData;
|
||||||
|
shiftPressed?: boolean;
|
||||||
|
altPressed?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SvgModuleCaptureEvent extends SvgKeyCaptureEvent {
|
||||||
|
keyId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SvgKeyboardCaptureEvent extends SvgModuleCaptureEvent {
|
||||||
|
moduleId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SvgKeyHoverEvent {
|
||||||
|
keyId: number;
|
||||||
|
event: MouseEvent;
|
||||||
|
over: boolean;
|
||||||
|
moduleId: number;
|
||||||
|
shiftPressed?: boolean;
|
||||||
|
altPressed?: boolean;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user