Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Presenting stimuli for fixed duration despite keypress

Hello,

I wondered if anyone knew how to present a word stimuli on the screen and have it remain for a fixed duration, even if I need to collect a keypress? They keypress automatically changes the screen to the next page/stimulus. I need to collect a keypress response, but I also need to have each stimuli on screen for 1800 ms. If anybody knows how/if this is possible, please let me know!

Thanks,

Nikita

Comments

  • Hi Nikita,

    The easiest way to do this is using coroutines , which allow you to run multiple items in parallel. In your case, you could present the stimulus sketchpad at time 0, a blank sketchpad at time 1800, and then have a keyboard_response active from time 0 to 2500 ms (or however long you want the response period to be).

    Important: coroutines are currently not supported by OSWeb, which is important if you want to run this experiment online.

    Cheers!

    Sebastiaan

    Buy Me A Coffee

  • Hi Sebastiaan,

    Thank you for the response. I am actually planning to eventually run it as an online experiment, so are there other options for doing this? Half of my stimuli require getting one keyboard response (either a "z" or "/"), while the other half require getting two (either a "z" or "/" paired with "space"). I understand that this will likely need an inline script, but I am not familiar with coding. I looked through other forum discussions that asked similar questions, but have been struggling for a long time now to find a code that will work for my experiment so that I can get keyboard responses within a fixed duration of 1800 ms (with an interstimulus interval of 200 ms), and also collect two correct keyboard responses for some of the presented word stimuli. Do you have any ideas?

    Let me know if this is confusing, or if you need more information. Again, thank you!

    Best,

    Nikita

  • Hi Nikita,

    One way to do this is to take control of key-press events directly in JavaScript. You can do this by registering a function that receives keydown events and processes them. To make sure that this function doesn't interfere with the rest of the experiment, you should have it unregister itself after the second keypress. The script below illustrates how to do this.

    The trick will be to insert this code into the Run phase of an inline_javascript item just before you start showing a series of sketchpad items, which simply can be presented as a slideshow without being intermixed with keyboard_response items.

    Hope this helps!

    Cheers,

    Sebastiaan

    function onKeyPress(event) {
        console.log(event)
        // On the first key press we simply log the key code and update
        // the n_key variable
        if (n_key === 0) {
            vars.first_key = event.code
            vars.first_rt = new Date().getTime() - t0
            n_key += 1
        // On the second key press we log the key code again and also
        // remove the key listener
        } else {
            vars.second_key = event.code
            vars.second_rt = new Date().getTime() - t0
            window.removeEventListener('keydown', onKeyPress)    
        }
    }
    
    let n_key = 0
    let t0 = new Date().getTime()
    window.addEventListener('keydown', onKeyPress)
    


    Buy Me A Coffee

  • Hello Sebastiaan,

    Thank you so much for the code. However, when I used it I got an error message that I've attached below. I did try to define the variable, but it did not work. Would you know how to possibly fix this error? Thank you so much!

    Best,

    Nikita


  • Right, this code requires that you run the experiment in a browser! The inline_javascript item works to some extent on the desktop, but not when you're really diving into the browser internals, like this script does.

    Buy Me A Coffee

  • Hi Sebastiaan,

    The code seems to work fine when I run the experiment in the browser. Thank you so much for all of your help!

    Best,

    Nikita

  • Hello Sebastiaan,

    I have a question again about this code you provided me. I no longer need to collect two key responses, but I still need to make sure my stimuli remains on screen for a fixed amount of time despite the keypress, so I modified this by deleting the second half of the code you provided in my experiment (I have the image attached below). While I am running through the experiment in Jatos it works fine, but when I export my results into Excel it shows that a key was pressed for stimuli even when I did not press any key.

    For example, during my practice run I pressed no keys for the first three stimuli, pressed the / key for the fourth stimuli, then did not press any keys for the remaining four stimuli. When I looked at my results, it showed that from the fourth stimuli and onward, the / keys were pressed even though I had only pressed it one time.

    Is there a way I can modify this code so that the experiment does not think I am pressing keys when I am not?

    Best,

    Nikita


  • Hi @nikitaadhikari1 ,

    This is probably because you're not resetting the vars.first_key variable at the start of the trial, thus getting carry-over effects. If you add add the following lines at the end of the script, this problem should go away:

    vars.first_key = ""
    vars.first_rt = 0
    

    Cheers!

    Sebastiaan

    Buy Me A Coffee

  • This worked perfectly, thank you so much!

    Best,

    Nikita

  • Hi Sebastiaan,

    Sorry for asking so many questions but I have one more for this experiment. For my program that requires getting two responses, I can only have responses such as "z" and "space" in one trial or "/" and "space" in one trial. If the participants press "z" and "/" in one trial, the results are unclear. Do you know how I can make it so that if the participants hit one of the keypresses, the other one becomes unavailable?

    For example, if they press the "z" key, I would like the "/" key to be unavailable and vice versa. The spacebar can remain available throughout. Is there a code I can add to have this in my experiment?

    Thank you in advance!

  • Hi @nikitaadhikari1 ,

    I think you can try to do this yourself 😀 To give you some idea of how to implement this.

    The event.code variable contains the key. If you define an allowed_response in your loop table, then you can check if event.code matches this (vars.allowed_response in the script), or if it matches a 'space' (which is always allowed). If you perform this check at the start of onKeyPressEvent() , then you can return from the function if the check fails, thus ignoring all keys except the allowed ones.

    Cheers!

    Sebastiaan

    Buy Me A Coffee

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games