Skip to content

Commit 6d0c0ea

Browse files
committed
isCode updated with tests
1 parent ad5ae5b commit 6d0c0ea

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/events/keyboard.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
* @requires core
66
*/
77
export function isCode(input) {
8+
const leftRightKeys = [
9+
'AltLeft', 'AltRight',
10+
'ShiftLeft', 'ShiftRight',
11+
'ControlLeft', 'ControlRight',
12+
'MetaLeft', 'MetaRight',
13+
];
14+
if (leftRightKeys.includes(input)) {
15+
return false;
16+
}
817
if (typeof input !== 'string') {
918
return false;
1019
}
@@ -913,6 +922,15 @@ function keyboard(p5, fn){
913922
* </div>
914923
*/
915924
function isCode(input) {
925+
const leftRightKeys = [
926+
'AltLeft', 'AltRight',
927+
'ShiftLeft', 'ShiftRight',
928+
'ControlLeft', 'ControlRight',
929+
'MetaLeft', 'MetaRight',
930+
];
931+
if (leftRightKeys.includes(input)) {
932+
return false;
933+
}
916934
if (typeof input !== 'string') {
917935
return false;
918936
}

test/unit/events/keyboard.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ suite('Keyboard Events', function() {
189189
assert.isTrue(isCode('Control'));
190190
assert.isTrue(isCode('ab'));
191191
});
192+
193+
test('returns false for strings for letright keys', function() {
194+
assert.isFalse(isCode('AltLeft'));
195+
assert.isFalse(isCode('ShiftRight'));
196+
});
192197

193198
test('handles edge cases correctly', function() {
194199
assert.isFalse(isCode('')); // empty string

0 commit comments

Comments
 (0)