From a219922b366f65743ae2b630082c1f90c9bd9467 Mon Sep 17 00:00:00 2001 From: Takuma Watanabe Date: Mon, 7 Sep 2020 16:30:10 +0900 Subject: [PATCH 1/2] Remove usage of depracated KeyboardEvent.keyCode - pushbutton-element - membrane-keypad-element --- src/membrane-keypad-element.ts | 6 +++--- src/pushbutton-element.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/membrane-keypad-element.ts b/src/membrane-keypad-element.ts index 0bdbbdc..5e223f6 100644 --- a/src/membrane-keypad-element.ts +++ b/src/membrane-keypad-element.ts @@ -2,7 +2,7 @@ import { customElement, html, LitElement, property, svg } from 'lit-element'; import { pinsFemalePattern } from './patterns/pins-female'; import { ElementPin } from './pin'; -const SPACE_KEY = 32; +const SPACE_KEYS = [' ', 'Spacebar']; const rowPositions = [10.7, 25, 39.3, 53.6]; const columnPositions = [7, 22, 37, 52]; @@ -81,9 +81,9 @@ export class MembraneKeypadElement extends LitElement { @touchstart=${() => this.down(text)} @touchend=${() => this.up(text)} @keydown=${(e: KeyboardEvent) => - e.keyCode === SPACE_KEY && this.down(text, e.currentTarget as SVGElement)} + SPACE_KEYS.includes(e.key) && this.down(text, e.currentTarget as SVGElement)} @keyup=${(e: KeyboardEvent) => - e.keyCode === SPACE_KEY && this.up(text, e.currentTarget as SVGElement)} + SPACE_KEYS.includes(e.key) && this.up(text, e.currentTarget as SVGElement)} > ${text} diff --git a/src/pushbutton-element.ts b/src/pushbutton-element.ts index 1c8be26..cd921b3 100644 --- a/src/pushbutton-element.ts +++ b/src/pushbutton-element.ts @@ -1,7 +1,7 @@ import { css, customElement, html, LitElement, property } from 'lit-element'; import { ElementPin } from './pin'; -const SPACE_KEY = 32; +const SPACE_KEYS = [' ', 'Spacebar']; @customElement('wokwi-pushbutton') export class PushbuttonElement extends LitElement { @@ -46,8 +46,8 @@ export class PushbuttonElement extends LitElement { @mouseup=${this.up} @touchstart=${this.down} @touchend=${this.up} - @keydown=${(e: KeyboardEvent) => e.keyCode === SPACE_KEY && this.down()} - @keyup=${(e: KeyboardEvent) => e.keyCode === SPACE_KEY && this.up()} + @keydown=${(e: KeyboardEvent) => SPACE_KEYS.includes(e.key) && this.down()} + @keyup=${(e: KeyboardEvent) => SPACE_KEYS.includes(e.key) && this.up()} > Date: Mon, 7 Sep 2020 21:30:52 +0900 Subject: [PATCH 2/2] Remove usage of depracated KeyboardEvent.keyCode - move `SPACE_KEYS` to common file --- src/membrane-keypad-element.ts | 3 +-- src/pushbutton-element.ts | 3 +-- src/utils/keys.ts | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) create mode 100644 src/utils/keys.ts diff --git a/src/membrane-keypad-element.ts b/src/membrane-keypad-element.ts index 5e223f6..e4170d6 100644 --- a/src/membrane-keypad-element.ts +++ b/src/membrane-keypad-element.ts @@ -1,8 +1,7 @@ import { customElement, html, LitElement, property, svg } from 'lit-element'; import { pinsFemalePattern } from './patterns/pins-female'; import { ElementPin } from './pin'; - -const SPACE_KEYS = [' ', 'Spacebar']; +import { SPACE_KEYS } from './utils/keys'; const rowPositions = [10.7, 25, 39.3, 53.6]; const columnPositions = [7, 22, 37, 52]; diff --git a/src/pushbutton-element.ts b/src/pushbutton-element.ts index cd921b3..a047c51 100644 --- a/src/pushbutton-element.ts +++ b/src/pushbutton-element.ts @@ -1,7 +1,6 @@ import { css, customElement, html, LitElement, property } from 'lit-element'; import { ElementPin } from './pin'; - -const SPACE_KEYS = [' ', 'Spacebar']; +import { SPACE_KEYS } from './utils/keys'; @customElement('wokwi-pushbutton') export class PushbuttonElement extends LitElement { diff --git a/src/utils/keys.ts b/src/utils/keys.ts new file mode 100644 index 0000000..97f8ce1 --- /dev/null +++ b/src/utils/keys.ts @@ -0,0 +1 @@ +export const SPACE_KEYS = [' ', 'Spacebar'];