forked from NetrisTV/ws-scrcpy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request NetrisTV#57 from HardBoiledSmith/DEV-14440
DEV-14440 [라미엘] iOS 도입 - 라미엘 안드로이드와 화면과 동작 일치시키기 W10~ NetrisTV#2 - 키보드 입력 기능 구현
- Loading branch information
Showing
8 changed files
with
274 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
{} | ||
{ | ||
"INCLUDE_APPL": true, | ||
"WDA_RUN_MJPEG_SERVER": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// TODO: HBsmith DEV-14440 | ||
|
||
import { WindowsKeyCodeToKey } from '../googDevice/WindowsKeyCodeToKey'; | ||
import { KeyToCodeMap, ToUpperCodeMap } from './KeyToCodeMap'; | ||
|
||
export interface KeyEventListener { | ||
onKeyEvent: (keyValue: string) => void; | ||
} | ||
|
||
export class KeyInputHandler { | ||
private static readonly listeners: Set<KeyEventListener> = new Set(); | ||
private static handler = (e: Event): void => { | ||
const event = e as KeyboardEvent; | ||
if (event.type !== 'keyup') { | ||
return; | ||
} | ||
|
||
let keyCode: string | undefined = event.code; | ||
if (!keyCode) { | ||
keyCode = WindowsKeyCodeToKey.get(event.keyCode); | ||
} | ||
if (!keyCode) { | ||
return; | ||
} | ||
|
||
let keyValue = KeyToCodeMap.get(keyCode); | ||
if (!keyValue) { | ||
return; | ||
} | ||
|
||
const shift = event.getModifierState('Shift') ? 1 : 0; | ||
const capsLock = event.getModifierState('CapsLock') ? 1 : 0; | ||
if (shift || capsLock) { | ||
if (keyValue.match(/[a-z]/i) && shift ^ capsLock) { | ||
keyValue = keyValue.toUpperCase(); | ||
} else if (shift) { | ||
const tt = ToUpperCodeMap.get(keyValue); | ||
if (tt) { | ||
keyValue = tt; | ||
} | ||
} | ||
} | ||
|
||
KeyInputHandler.listeners.forEach((listener) => { | ||
if (keyValue) { | ||
listener.onKeyEvent(keyValue); | ||
} | ||
}); | ||
e.preventDefault(); | ||
}; | ||
private static attachListeners(): void { | ||
document.body.addEventListener('keyup', this.handler); | ||
} | ||
private static detachListeners(): void { | ||
document.body.removeEventListener('keyup', this.handler); | ||
} | ||
public static addEventListener(listener: KeyEventListener): void { | ||
if (!this.listeners.size) { | ||
this.attachListeners(); | ||
} | ||
this.listeners.add(listener); | ||
} | ||
public static removeEventListener(listener: KeyEventListener): void { | ||
this.listeners.delete(listener); | ||
if (!this.listeners.size) { | ||
this.detachListeners(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import UIEventsCode from '../UIEventsCode'; | ||
|
||
export const KeyToCodeMap = new Map([ | ||
[UIEventsCode.Backquote, '`'], | ||
[UIEventsCode.Backslash, '\\'], | ||
[UIEventsCode.BracketLeft, '('], | ||
[UIEventsCode.BracketRight, ')'], | ||
[UIEventsCode.Comma, ','], | ||
[UIEventsCode.Digit0, '0'], | ||
[UIEventsCode.Digit1, '1'], | ||
[UIEventsCode.Digit2, '2'], | ||
[UIEventsCode.Digit9, '9'], | ||
[UIEventsCode.Digit3, '3'], | ||
[UIEventsCode.Digit4, '4'], | ||
[UIEventsCode.Digit5, '5'], | ||
[UIEventsCode.Digit6, '6'], | ||
[UIEventsCode.Digit7, '7'], | ||
[UIEventsCode.Digit8, '8'], | ||
[UIEventsCode.Equal, '='], | ||
// [UIEventsCode.IntlRo, ''], | ||
[UIEventsCode.IntlYen, '₩'], | ||
[UIEventsCode.KeyA, 'a'], | ||
[UIEventsCode.KeyB, 'b'], | ||
[UIEventsCode.KeyC, 'c'], | ||
[UIEventsCode.KeyD, 'd'], | ||
[UIEventsCode.KeyE, 'e'], | ||
[UIEventsCode.KeyF, 'f'], | ||
[UIEventsCode.KeyG, 'g'], | ||
[UIEventsCode.KeyH, 'h'], | ||
[UIEventsCode.KeyI, 'i'], | ||
[UIEventsCode.KeyJ, 'j'], | ||
[UIEventsCode.KeyK, 'k'], | ||
[UIEventsCode.KeyL, 'l'], | ||
[UIEventsCode.KeyM, 'm'], | ||
[UIEventsCode.KeyN, 'n'], | ||
[UIEventsCode.KeyO, 'o'], | ||
[UIEventsCode.KeyP, 'p'], | ||
[UIEventsCode.KeyQ, 'q'], | ||
[UIEventsCode.KeyR, 'r'], | ||
[UIEventsCode.KeyS, 's'], | ||
[UIEventsCode.KeyT, 't'], | ||
[UIEventsCode.KeyU, 'u'], | ||
[UIEventsCode.KeyV, 'v'], | ||
[UIEventsCode.KeyW, 'w'], | ||
[UIEventsCode.KeyX, 'x'], | ||
[UIEventsCode.KeyY, 'y'], | ||
[UIEventsCode.KeyZ, 'z'], | ||
[UIEventsCode.Minus, '-'], | ||
[UIEventsCode.Period, '.'], | ||
[UIEventsCode.Quote, "'"], | ||
[UIEventsCode.Semicolon, ';'], | ||
[UIEventsCode.Slash, '/'], | ||
// [UIEventsCode.KanaMode, ''], | ||
// [UIEventsCode.Delete, ''], | ||
// [UIEventsCode.End, ''], | ||
// [UIEventsCode.Help, ''], | ||
// [UIEventsCode.Home, ''], | ||
// [UIEventsCode.Insert, ''], | ||
// [UIEventsCode.PageDown, ''], | ||
// [UIEventsCode.PageUp, ''], | ||
// [UIEventsCode.AltLeft, ''], | ||
// [UIEventsCode.AltRight, ''], | ||
[UIEventsCode.Backspace, '\b'], | ||
// [UIEventsCode.CapsLock, ''], | ||
// [UIEventsCode.ControlLeft, ''], | ||
// [UIEventsCode.ControlRight, ''], | ||
[UIEventsCode.Enter, '\n'], | ||
// [UIEventsCode.MetaLeft, KeyEvent.KEYCODE_META_LEFT], | ||
// [UIEventsCode.MetaRight, KeyEvent.KEYCODE_META_RIGHT], | ||
// [UIEventsCode.ShiftLeft, KeyEvent.KEYCODE_SHIFT_LEFT], | ||
// [UIEventsCode.ShiftRight, KeyEvent.KEYCODE_SHIFT_RIGHT], | ||
[UIEventsCode.Space, ' '], | ||
[UIEventsCode.Tab, '\t'], | ||
// [UIEventsCode.ArrowLeft, KeyEvent.KEYCODE_DPAD_LEFT], | ||
// [UIEventsCode.ArrowUp, KeyEvent.KEYCODE_DPAD_UP], | ||
// [UIEventsCode.ArrowRight, KeyEvent.KEYCODE_DPAD_RIGHT], | ||
// [UIEventsCode.ArrowDown, KeyEvent.KEYCODE_DPAD_DOWN], | ||
|
||
// [UIEventsCode.NumLock, KeyEvent.KEYCODE_NUM_LOCK], | ||
[UIEventsCode.Numpad0, '0'], | ||
[UIEventsCode.Numpad1, '1'], | ||
[UIEventsCode.Numpad2, '2'], | ||
[UIEventsCode.Numpad3, '3'], | ||
[UIEventsCode.Numpad4, '4'], | ||
[UIEventsCode.Numpad5, '5'], | ||
[UIEventsCode.Numpad6, '6'], | ||
[UIEventsCode.Numpad7, '7'], | ||
[UIEventsCode.Numpad8, '8'], | ||
[UIEventsCode.Numpad9, '9'], | ||
// [UIEventsCode.NumpadAdd, KeyEvent.KEYCODE_NUMPAD_ADD], | ||
[UIEventsCode.NumpadComma, ','], | ||
[UIEventsCode.NumpadDecimal, '.'], | ||
[UIEventsCode.NumpadDivide, '/'], | ||
[UIEventsCode.NumpadEnter, '\n'], | ||
[UIEventsCode.NumpadEqual, '='], | ||
[UIEventsCode.NumpadMultiply, '*'], | ||
[UIEventsCode.NumpadParenLeft, '('], | ||
[UIEventsCode.NumpadParenRight, ')'], | ||
[UIEventsCode.NumpadSubtract, '-'], | ||
|
||
// [UIEventsCode.Escape, ''], | ||
// [UIEventsCode.F1, ''], | ||
// [UIEventsCode.F2, ''], | ||
// [UIEventsCode.F3, ''], | ||
// [UIEventsCode.F4, ''], | ||
// [UIEventsCode.F5, ''], | ||
// [UIEventsCode.F6, ''], | ||
// [UIEventsCode.F7, ''], | ||
// [UIEventsCode.F8, ''], | ||
// [UIEventsCode.F9, ''], | ||
// [UIEventsCode.F10, ''], | ||
// [UIEventsCode.F11, ''], | ||
// [UIEventsCode.F12, ''], | ||
// [UIEventsCode.Fn, ''], | ||
// [UIEventsCode.PrintScreen, ''], | ||
// [UIEventsCode.Pause, ''], | ||
]); | ||
|
||
export const ToUpperCodeMap = new Map([ | ||
['`', '~'], | ||
['1', '!'], | ||
['2', '@'], | ||
['3', '#'], | ||
['4', '$'], | ||
['5', '%'], | ||
['6', '^'], | ||
['7', '&'], | ||
['8', '*'], | ||
['9', '('], | ||
['0', ')'], | ||
['-', '_'], | ||
['+', '+'], | ||
['[', '{'], | ||
[']', '}'], | ||
['\\', '|'], | ||
[';', ':'], | ||
["'", '"'], | ||
[',', '<'], | ||
['.', '>'], | ||
['/', '?'], | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters