Issue with key press during timer

PennController for IBEX Forums Support Issue with key press during timer

Tagged: ,

This topic contains 4 replies, has 2 voices, and was last updated by Avatar carlap 4 months, 3 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #6031
    Avatar
    carlap
    Participant

    Hi,

    I have an experiment and it has the following elements

    1. An audio of a number plays then there is a timer
    2. A second audio of a number plays and there is another timer
    3. Text appears and there is a timer (300 ms). The task is to determine if the text represents the product of the 2 audio numbers.
    4. The text disappears and there is a newKey step to record the answer.

    The problem is if the subject tries to answer during the 300 ms timer that controls the appearance of the text, the answer is not captured and then the subject will multiple press until the answer is accepted and this causes problems with the reaction time.

    A sample of the code is below. Any thoughts are greatly appreciated.

        newText("num", row.Solution)
            .settings.css ("color","white")
            .settings.css("font-size", "200px")
            .print()
          ,
        newTimer(300) .start() .wait() 
        ,
    
         getText("num")
         .remove()
        ,
       
         newKey("pressOnArrow", "ArrowLeft", "ArrowRight") .log() .callback( getTimer 
    ("timeout").stop() ).log("all") , newTimer("timeout", 5000).start().log().wait() , getKey 
    ("pressOnArrow") .disable() ) .log( "Correct_answer"  , row.Correct_answer   )	
         .log( "ID" , getVar("ID")
    #6033
    Jeremy
    Jeremy
    Keymaster

    Hi,

    I’m not sure I understand the problem. When I try your code, my first keypress after the 300ms timer has elapsed is captured, regardless of whether (and how many times) I tried pressing a key during those 300ms.

    Are you saying you want your results file to report keypresses that happen during the 300ms, but still validate keypresses only after the 300ms? If so, this is one way of doing it:

        newText("num", row.Solution)
            .css("color","white")
            .css("font-size", "200px")
            .print()
        ,
        newKey("pressOnArrow", "ArrowLeft", "ArrowRight").log("all")
        ,
        newTimer(300).start().wait() 
        ,
        getText("num").remove()
        ,
        getKey("pressOnArrow").callback( getTimer("timeout").stop() )
        , 
        newTimer("timeout", 5000).start().log().wait()
        ,
        getKey("pressOnArrow").disable() 
    )
    .log( "Correct_answer"  , row.Correct_answer   )	
    .log( "ID" , getVar("ID")

    ie. you create the Key element before the 300ms timer, but only make it stop the timeout timer after those 300ms. You’ll be able to tell whether a key was pressed during the 300ms by comparing pressOnArrow‘s timestamps with timeout‘s timestamp in your results file.

    Jeremy

    #6036
    Avatar
    carlap
    Participant

    Hi. Thanks for the quick response. I´m sorry if it isn´t clear. What I would like is for the subject to be able to respond both during and after the 300ms, while the text is on the screen and also during the 5 seconds waiting time after it has been removed. But, I need a response during the 300ms to cancel the second waiting time. That is a response during the 300ms is captured and then the program just moves on to the next trial. A response after the 300ms sould have the same effect, captured and move on. Thanks!

    #6037
    Jeremy
    Jeremy
    Keymaster

    Thanks for the clarification. Then this should do what you want:

        newText("num", row.Solution)
            .css("color","white")
            .css("font-size", "200px")
            .print()
        ,
        newKey("pressOnArrow", "ArrowLeft", "ArrowRight")
            .log("all")
            .callback( 
                getTimer("exposure").stop(),
                getTimer("timeout").stop()
            )
        ,
        newTimer("exposure", 300).start().wait() 
        ,
        getText("num").remove()
        ,
        getKey("pressOnArrow").test.pressed()
            .failure( newTimer("timeout", 5000).start().log().wait() )
        ,
        getKey("pressOnArrow").disable()
    )
    .log( "Correct_answer"  , row.Correct_answer   )	
    .log( "ID" , getVar("ID")

    Let me know if problems persist

    Jeremy

    #6040
    Avatar
    carlap
    Participant

    That works great! You rock! Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.