Skip to content

Commit dd458c0

Browse files
committed
changed keyboard.js and added the updated objects in costants.js file
1 parent 2ec3557 commit dd458c0

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

src/core/constants.js

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -879,92 +879,104 @@ export const MITER = 'miter';
879879
* @final
880880
*/
881881
export const AUTO = 'auto';
882-
882+
// INPUT
883883
/**
884-
* @typedef {18} ALT
884+
* @typedef {'AltLeft' | 'AltRight'} ALT
885885
* @property {ALT} ALT
886886
* @final
887887
*/
888-
// INPUT
889-
export const ALT = 18;
888+
export const ALT = 'AltLeft';
889+
890890
/**
891-
* @typedef {8} BACKSPACE
891+
* @typedef {'Backspace'} BACKSPACE
892892
* @property {BACKSPACE} BACKSPACE
893893
* @final
894894
*/
895-
export const BACKSPACE = 8;
895+
export const BACKSPACE = 'Backspace';
896+
896897
/**
897-
* @typedef {17} CONTROL
898+
* @typedef {'ControlLeft' | 'ControlRight'} CONTROL
898899
* @property {CONTROL} CONTROL
899900
* @final
900901
*/
901-
export const CONTROL = 17;
902+
export const CONTROL = 'ControlLeft';
903+
902904
/**
903-
* @typedef {46} DELETE
905+
* @typedef {'Delete'} DELETE
904906
* @property {DELETE} DELETE
905907
* @final
906908
*/
907-
export const DELETE = 46;
909+
export const DELETE = 'Delete';
910+
908911
/**
909-
* @typedef {40} DOWN_ARROW
912+
* @typedef {'ArrowDown'} DOWN_ARROW
910913
* @property {DOWN_ARROW} DOWN_ARROW
911914
* @final
912915
*/
913-
export const DOWN_ARROW = 40;
916+
export const DOWN_ARROW = 'ArrowDown';
917+
914918
/**
915-
* @typedef {13} ENTER
919+
* @typedef {'Enter'} ENTER
916920
* @property {ENTER} ENTER
917921
* @final
918922
*/
919-
export const ENTER = 13;
923+
export const ENTER = 'Enter';
924+
920925
/**
921-
* @typedef {27} ESCAPE
926+
* @typedef {'Escape'} ESCAPE
922927
* @property {ESCAPE} ESCAPE
923928
* @final
924929
*/
925-
export const ESCAPE = 27;
930+
export const ESCAPE = 'Escape';
931+
926932
/**
927-
* @typedef {37} LEFT_ARROW
933+
* @typedef {'ArrowLeft'} LEFT_ARROW
928934
* @property {LEFT_ARROW} LEFT_ARROW
929935
* @final
930936
*/
931-
export const LEFT_ARROW = 37;
937+
export const LEFT_ARROW = 'ArrowLeft';
938+
932939
/**
933-
* @typedef {18} OPTION
940+
* @typedef {'AltLeft' | 'AltRight'} OPTION
934941
* @property {OPTION} OPTION
935942
* @final
936943
*/
937-
export const OPTION = 18;
944+
export const OPTION = 'AltLeft';
945+
938946
/**
939-
* @typedef {13} RETURN
947+
* @typedef {'Enter'} RETURN
940948
* @property {RETURN} RETURN
941949
* @final
942950
*/
943-
export const RETURN = 13;
951+
export const RETURN = 'Enter';
952+
944953
/**
945-
* @typedef {39} RIGHT_ARROW
954+
* @typedef {'ArrowRight'} RIGHT_ARROW
946955
* @property {RIGHT_ARROW} RIGHT_ARROW
947956
* @final
948957
*/
949-
export const RIGHT_ARROW = 39;
958+
export const RIGHT_ARROW = 'ArrowRight';
959+
950960
/**
951-
* @typedef {16} SHIFT
961+
* @typedef {'ShiftLeft' | 'ShiftRight'} SHIFT
952962
* @property {SHIFT} SHIFT
953963
* @final
954964
*/
955-
export const SHIFT = 16;
965+
export const SHIFT = 'ShiftLeft';
966+
956967
/**
957-
* @typedef {9} TAB
968+
* @typedef {'Tab'} TAB
958969
* @property {TAB} TAB
959970
* @final
960971
*/
961-
export const TAB = 9;
972+
export const TAB = 'Tab';
973+
962974
/**
963-
* @typedef {38} UP_ARROW
975+
* @typedef {'ArrowUp'} UP_ARROW
964976
* @property {UP_ARROW} UP_ARROW
965977
* @final
966978
*/
967-
export const UP_ARROW = 38;
979+
export const UP_ARROW = 'ArrowUp';
968980

969981
// RENDERING
970982
/**

src/events/keyboard.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,16 @@ function keyboard(p5, fn){
440440
* </div>
441441
*/
442442
fn._onkeydown = function(e) {
443-
if (this._downKeys[e.which]) {
443+
if (this._downKeys[e.code]) {
444444
// prevent multiple firings
445445
return;
446446
}
447447
this.isKeyPressed = true;
448448
this.keyIsPressed = true;
449449
this.keyCode = e.which;
450-
this._downKeys[e.which] = true;
451-
this.key = e.key || String.fromCharCode(e.which) || e.which;
450+
this._code = e.code;
451+
this.key = e.key;
452+
this._downKeys[e.code] = true;
452453
const context = this._isGlobal ? window : this;
453454
if (typeof context.keyPressed === 'function' && !e.charCode) {
454455
const executeDefault = context.keyPressed(e);

0 commit comments

Comments
 (0)