File tree 2 files changed +10
-25
lines changed
2 files changed +10
-25
lines changed Original file line number Diff line number Diff line change 6
6
*/
7
7
export function isCode ( input ) {
8
8
const leftRightKeys = [
9
- 'AltLeft' , 'AltRight ',
10
- 'ShiftLeft' , 'ShiftRight ',
11
- 'ControlLeft' , 'ControlRight ',
12
- 'MetaLeft' , 'MetaRight ',
9
+ 'Alt ' ,
10
+ 'Shift ' ,
11
+ 'Control ' ,
12
+ 'Meta ' ,
13
13
] ;
14
14
if ( leftRightKeys . includes ( input ) ) {
15
15
return false ;
@@ -924,21 +924,6 @@ function keyboard(p5, fn){
924
924
* </code>
925
925
* </div>
926
926
*/
927
- function isCode ( input ) {
928
- const leftRightKeys = [
929
- 'AltLeft' , 'AltRight' ,
930
- 'ShiftLeft' , 'ShiftRight' ,
931
- 'ControlLeft' , 'ControlRight' ,
932
- 'MetaLeft' , 'MetaRight' ,
933
- ] ;
934
- if ( leftRightKeys . includes ( input ) ) {
935
- return false ;
936
- }
937
- if ( typeof input !== 'string' ) {
938
- return false ;
939
- }
940
- return input . length > 1 ;
941
- }
942
927
943
928
fn . keyIsDown = function ( input ) {
944
929
if ( isCode ( input ) ) {
Original file line number Diff line number Diff line change @@ -183,16 +183,16 @@ suite('Keyboard Events', function() {
183
183
} ) ;
184
184
185
185
test ( 'returns true for multi-character strings' , function ( ) {
186
- assert . isTrue ( isCode ( 'Enter ' ) ) ;
186
+ assert . isTrue ( isCode ( 'ShiftLeft ' ) ) ;
187
187
assert . isTrue ( isCode ( 'ArrowUp' ) ) ;
188
- assert . isTrue ( isCode ( 'Shift' ) ) ;
189
- assert . isTrue ( isCode ( 'Control' ) ) ;
190
188
assert . isTrue ( isCode ( 'ab' ) ) ;
191
189
} ) ;
192
190
193
- test ( 'returns false for strings for letright keys' , function ( ) {
194
- assert . isFalse ( isCode ( 'AltLeft' ) ) ;
195
- assert . isFalse ( isCode ( 'ShiftRight' ) ) ;
191
+ test ( 'returns false/true for apppropriate leftright keys and codes' , function ( ) {
192
+ assert . isFalse ( isCode ( 'Alt' ) ) ;
193
+ assert . isFalse ( isCode ( 'Shift' ) ) ;
194
+ assert . isTrue ( isCode ( 'AltLeft' ) ) ;
195
+ assert . isTrue ( isCode ( 'ShiftLeft' ) ) ;
196
196
} ) ;
197
197
198
198
test ( 'handles edge cases correctly' , function ( ) {
You can’t perform that action at this time.
0 commit comments