Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getKeyboardResponse can return a lower case version of the key in some circumstances #3325

Closed
TAOKA-Daiki opened this issue Jun 21, 2024 · 6 comments · Fixed by #3338
Closed
Milestone

Comments

@TAOKA-Daiki
Copy link

TAOKA-Daiki commented Jun 21, 2024

The description of the parameter choices in html-keyboard-response in jsPsych v7 seems to be incorrect.

jsPsych v7 plugin page of html-keyboard-response

Enter key was detected with 'enter', not 'Enter'.
The down arrow key was detected with 'arrowdown', not 'ArrowDown'.
The version of jsPsych used for testing was V7.3.4.

At least as of 2024/06/21, the reference link attached in the table was not informative.

Please correct the description of the plugin page and provide a list of correct key names that jsPsych can accept.
Thank you in advance.

image

@jodeleeuw
Copy link
Member

Hi @TAOKA-Daiki,

I just double checked this and, at least in Chromium, the event.key property is Enter for the enter key and ArrowDown for the arrow down key. What browser did you test this on?

@TAOKA-Daiki
Copy link
Author

Thank you for early reply and checking, @jodeleeuw.

My jsPsych v7 program runs on the Google Chrome version 126.0.6478.61 (64 bit for Windows).
I have just tried updating Chrome to the latest version (126.0.6478.115) and tested my program again, but the issue persisted.
The same was true on Microsoft Edge version 126.0.2592.68.

@jodeleeuw
Copy link
Member

Can you clarify what the issue is?

The key strings are not case sensitive, so if you are using "enter" that will work just as well as "Enter". When the event is generated by the browser it uses the capitalization that is shown in the documentation. Are you seeing a case where "Enter" does not work but "enter" does?

@TAOKA-Daiki
Copy link
Author

TAOKA-Daiki commented Jun 22, 2024

I have checked the source code of jsPsych.js and understood the reason for the issue.

As you said, the areResponsesCaseSensitive property of the KeyboardListerAPI in jsPsych v7 is false by default (in line 681 of jsPsych.js). And in the getKeyboardResponse method, the list of key names given to valid_responses is converted to lowercase (in line 741 of jsPsych.js).

I am currently working on tweaking my custom plugin (modified from plugin-html-keyboard-response.js). My custom plugin accepts numeric and Backspace keys and displays the input value on screen, and then participant determines the input by pressing the Enter key.

What I have stuck this time is the after_response = (info) => {} function in the custom plugin.
As I mentioned above, inside jsPsych v7, key names are converted to lowercase.
Therefore, in the after_response function, the key cannot be detected correctly unless info.key == 'enter' instead of info.key == 'Enter'. On the other hand, in the info.choices property of trial, both 'Enter' and 'enter' are valid.
I could not understand this behavior and mistakenly thought that all key names had to be specified in lowercase.

Understanding the internal processing of jsPsych helped me understand the reason for the problem.
The content of the plugin page is not completely incorrect. But in any case, it seems to me that this behavior is likely to be misleading (especially in a case like mine).

@jodeleeuw
Copy link
Member

Thanks for clarifying!

I think we should consider outputting the standard Enter instead of enter for the info.key. @jspsych/core any concerns?

@jodeleeuw jodeleeuw added this to the 8.0 milestone Jun 22, 2024
@jodeleeuw jodeleeuw changed the title Description of the plugin 'html-keyboard-response v1.1.3' seems incorrect getKeyboardResponse can return a lower case version of the key in some circumstances Jun 22, 2024
jodeleeuw added a commit that referenced this issue Jul 11, 2024
@jodeleeuw jodeleeuw linked a pull request Jul 11, 2024 that will close this issue
@jodeleeuw
Copy link
Member

This will be fixed in v8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants