Skip to content

Commit e0c4a31

Browse files
committed
minor changes for single digit input
1 parent 0ce4e89 commit e0c4a31

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/events/keyboard.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ export function isCode(input) {
88
if (typeof input !== 'string') {
99
return false;
1010
}
11-
12-
if (input.length === 1 && /[0-9]/.test(input)) {
13-
return true;
14-
}
15-
1611
return input.length > 1;
1712
}
1813
function keyboard(p5, fn){
@@ -636,8 +631,10 @@ function keyboard(p5, fn){
636631
this.code = null;
637632
} else {
638633
// If other keys are still pressed, update code to the last pressed key
634+
const lastPressedCode = Object.keys(this._downKeyCodes).pop();
635+
this.code = lastPressedCode;
639636
const lastPressedKey = Object.keys(this._downKeys).pop();
640-
this.code = lastPressedKey;
637+
this.key = lastPressedKey;
641638
}
642639

643640
const context = this._isGlobal ? window : this;
@@ -920,9 +917,6 @@ function keyboard(p5, fn){
920917
if (typeof input !== 'string') {
921918
return false;
922919
}
923-
if (input.length === 1 && /[0-9]/.test(input)) {
924-
return true;
925-
}
926920
return input.length > 1;
927921
}
928922

test/unit/events/keyboard.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ suite('Keyboard Events', function() {
190190
assert.isFalse(isCode([]));
191191
});
192192

193-
test('returns false for single non-digit characters', function() {
193+
test('returns false for single non-digit and digit characters', function() {
194194
assert.isFalse(isCode('a'));
195195
assert.isFalse(isCode('Z'));
196-
assert.isFalse(isCode('!'));
196+
assert.isFalse(isCode('1'));
197+
assert.isFalse(isCode('2'));
197198
assert.isFalse(isCode(' '));
198199
});
199200

0 commit comments

Comments
 (0)