Recording keypress with a timer

PennController for IBEX Forums Support Recording keypress with a timer

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6535
    suphasiree
    Participant

    Hi Jeremy!

    My experiment involves playing audio sentences followed by a comprehension question, and at the end of each trial I have a prompt asking whether they experienced any issues hearing the audio. In the rare occasion that they encountered issues they should press the Y key, but most of the time they can just press the spacebar to continue. This “audio issue” prompt stays on the screen for a few seconds (via a timer).

    I tried using .log() to record which key they pressed (Y key or spacebar), but I haven’t got it to work. In the results file I only see that the Parameter says “PressedKey”, with no corresponding Value.

    Here is the relevant part of the code:

       newTimer("time limit", 8000)
            .log()
            .start()
        ,
        newText("checkaudio", "<i>Audio problem?</i>  If so, press <b>Y</b>. <br><br><i>Otherwise, press the spacebar to continue.</i>")
            .css("margin-top", "5em") 
        ,
        newKey("audioanswer", "Y", " ")
            .log("last")
            .setVar("inputanswer")
            .callback( getTimer("time limit").stop() )
        ,
        getTimer("time limit")
            .wait()
        ,
        getText("checkaudio").remove()
        ,
        newText("nextsentence", "When you're ready, press the spacebar to see the next sentence.")
            .css("margin-top", "2em") 
            .italic()
        ,
        newKey(" ")
            .wait()
        ,
        newVar("inputanswer")
            .global() 
            .set( getTextInput("inputanswer")) 
        ,
        newVar("audioanswer")
            .global()
            .set(getKey("audioanswer"))

    Thank you in advance!

    #6536
    Jeremy
    Keymaster

    Hi,

    Key elements remain active until you explicitly disable them. By default, log will only report keypresses that validate a wait command on the Key element. In your case, you have no wait command on the “audioanswer” Key element, so you use log("last"). Because you end the trial by requiring that your participant press the spacebar, and because that key is also part of the “audioanswer” keys, the last keypress that was captured by your “audioanswer” Key element necessarily is a spacebar, which is reported as a space character in your results file (...,Key,audioanswer,PressedKey, ,1611166764724,...)

    Here’s one solution to your problem:

    newKey("audioanswer", "Y", " ")
        .log("last")
        .setVar("inputanswer")
        .callback( getTimer("time limit").stop() )
    ,
    getTimer("time limit")
        .wait()
    ,
    getKey("audioanswer").disable()

    Let me know if you have questions

    Jeremy

    #6537
    suphasiree
    Participant

    Hi Jeremy,

    That worked perfectly, thank you for your help!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.