Skip to content

Commit

Permalink
Merge branch 'fix-wasd-navigation' of git://github.com/vincentfretin/…
Browse files Browse the repository at this point in the history
…hubs into vincentfretin-fix-wasd-navigation
  • Loading branch information
netpro2k committed Mar 16, 2021
2 parents a7cb591 + 2b015d1 commit c544888
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/systems/userinput/devices/keyboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { paths } from "../paths";
import { ArrayBackedSet } from "../array-backed-set";

const CODE_TO_KEY = {
"KeyW": "w",
"KeyA": "a",
"KeyS": "s",
"KeyD": "d",
"KeyQ": "q",
"KeyE": "e",
};

export class KeyboardDevice {
constructor() {
this.seenKeys = new ArrayBackedSet();
Expand Down Expand Up @@ -45,7 +55,10 @@ export class KeyboardDevice {
this.keys = {};
this.seenKeys.clear();
} else {
const key = event.key.toLowerCase();
let key = event.key.toLowerCase();
// Use event.code and not event.key for wasdqe controls so this works
// for non QWERTY keyboards.
key = (event.code && CODE_TO_KEY[event.code]) || key;
this.keys[key] = event.type === "keydown";
this.seenKeys.add(key);
}
Expand Down

0 comments on commit c544888

Please sign in to comment.