Clearing the Key Buffer Demo Experiment Run Experiment

Clearing the Key Buffer

Jaap Murre

If you use an awaitkey() the subjects's response will 'linger' even after the awaitkey() call and will remain active. E.g., an Enter key stroke will 'linger' and remain active and will 'click' the following OK button. This can easily be prevented by using preventDefault(), a standard JavaScript function. See the code.

If you are a registered user and signed in, you can here copy this script and its stimuli to your own account, where you can edit it and change it in any way you want.

It is absolutely free to register (no credit card info asked!). You can then instantly copy this experiment with one click and edit it, change its accompanying texts, its landing page, stimuli, etc. Invite your colleagues, friends, or students to check out your experiment. There is no limit on how many people can do your experiment, even with a free account.

The catch? There is no catch! Just keep in mind that with a free account, you cannot collect data. For teaching that is usually not a problem. For research, prepaid data collection (unlimited subjects) starts as low as €10.00 for a 10-day period.

// If you do an awaitkey() the subjects's response will 'linger' even after
// the awaitkey() call and will remain active. E.g., an Enter key stroke
// will remain active and will 'click' the following OK button.

text("Press Enter");
awaitkey("ENTER"); // This will work
// The Enter key stroke is NOT gone
// It will click the following input's OK button and the subject will not see it
input("You probably don't see this input at all"); 
text("Did you see the input control? Probably not. How about the following one?");
await(2000);


// SOLUTION
text("Press Enter");
var e = awaitkey("ENTER"); // We now keep the event returned in variable e
e.event.preventDefault();  // This 'disactivates' the key stroke

// It will no longer click the following input's OK button 
input("You should see this input now"); 
text("See the script for how we did this.");
await(2000);
This experiment has no files of this type
This experiment has no files of this type
This experiment has no files of this type
This experiment has no YouTube links
This experiment has no files of this type