Pages

Reaction timer on the linux terminal

Here is a script that can be used as a reaction timer on the terminal of linux.

Reaction timers are used to calculate the time a user takes to react to an input or stimuli.

There are two variants one that can be run in the text mode and another that can be run in the terminal of GUI mode.

Text mode:

The following will turn the caps-lock led on and expects the user to hit any key on the keyboard as soon as the led is turned on. The time taken by the user to hit the key after turning on the led is displayed as the reaction time.

We will need to use two separate scripts one to light up the led and the other to record the reaction.

led_on.sh



key.sh



Save both the scripts and give them execute permissions



Note: that both have to saved in the same directory.

Now execute the script "led_on.sh".



After a delay between one to ten seconds the led of caps-lock will turn on.
The user has to hit any key on the keyboard as soon as it turns on.
The script will display the number of seconds or fraction of seconds the user took to react.

Note: The command "setleds" works only in the text mode, thus this script is not useful in the terminal of a GUI mode.

Note: You need to have permission to create files in the directory where you run this script as it creates a temp file during the execution and deletes it at the end.

GUI mode:

For the GUI mode the same script is modified and instead of turning on the led, the message "ON" is displayed and the user is expected to hit any key on the keyboard as soon as the message appears on the screen. The time user takes to hit the keyboard after the message appears is calculated and displayed as the reaction time.

led_on.sh



key.sh



The steps are same as for the script above, only difference being that instead of the led turning on, the message "ON" will be displayed on the terminal.


2 comments:

  1. Shouldn't the line /usr/bin/time -o temp -f "real %e" ./key be /usr/bin/time -o temp -f "real %e" ./key.sh ?

    ReplyDelete
    Replies
    1. Thanks for the correction :-) have updated it .

      Delete