Started working on keyboard input
This commit is contained in:
parent
11f658afcc
commit
cfe313c9a3
|
@ -6,6 +6,16 @@ export default class extends Controller {
|
|||
static targets = [ "key" ];
|
||||
static outlets = [ "playfield" ];
|
||||
|
||||
onKeyPress(ev) {
|
||||
if ((ev.key >= 'a') && (ev.key >= 'z')) {
|
||||
ev.preventDefault();
|
||||
this.playfieldOutlet.tappedKey(ev.key);
|
||||
} else if ((ev.key >= 'A') && (ev.key >= 'Z')) {
|
||||
ev.preventDefault();
|
||||
this.playfieldOutlet.tappedKey(ev.key.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
tappedKey(ev) {
|
||||
ev.preventDefault();
|
||||
|
||||
|
|
|
@ -18,7 +18,11 @@
|
|||
|
||||
<div data-controller="keyboard"
|
||||
data-keyboard-playfield-outlet=".playfield"
|
||||
data-action="guessResults@window->keyboard#colorizeKeys resetKeyColors@window->keyboard#resetKeyColors">
|
||||
data-action="
|
||||
keypress@window->keyboard#onKeyPress
|
||||
guessResults@window->keyboard#colorizeKeys
|
||||
resetKeyColors@window->keyboard#resetKeyColors
|
||||
">
|
||||
<div>
|
||||
<button data-keyboard-target="key" data-action="keyboard#tappedKey" data-key="q">q</button>
|
||||
<button data-keyboard-target="key" data-action="keyboard#tappedKey" data-key="w">w</button>
|
||||
|
|
Loading…
Reference in a new issue