Howdy, Stranger!

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

Supported by

[solved] Key realease

edited January 2013 in OpenSesame

Hi
Does anyone know the best way to record a key release (rather than Press) in Opensesame? The participant will hold the response key (SPACEBAR) from the start of the trial until a certain event does or doesn't occur. I will need RTs recorded from the onset of an object (a new event) that will signify key release (or not) to the actual key release and also, from key release to a second mouse click (well, actually a touch screen input). Any help much appreciated

Comments

  • edited February 2014

    Hi JasT.

    I had the same need in the past, so I can show you my solution (which requires a piece of python code).

    I used pyglet KeyStateHandler function inside psycho backend, so I don't know if you can use the same function inside another backend. This is a simple code that you can adapt to your needs.

    from psychopy import visual, core
    from pyglet.window import key
    response = key.KeyStateHandler()
    self.experiment.window.winHandle.push_handlers(response)
    win = self.experiment.window
    time = core.Clock()
    press = visual.TextStim(win, pos=(0,0), text='Hold down the SPACEBAR...')
    release = visual.TextStim(win, pos=(0,0), text='When you want, release the SPACEBAR')
    # spacebar not pressed
    while not response[key.SPACE]:
        press.draw()
        win.flip()
    t1 = time.getTime() # spacebar pressed! (first timestamp)
    while response[key.SPACE]:
        release.draw()
        win.flip()
    t2 = time.getTime() # spacebar released! (second timestamp)
    spacebar_time = t2-t1 # compute the key pressing time
    

    I don't know if there is a simpler method. Hope this helps.

    Andrea

  • edited 4:49AM

    Thanks that's helpful - it makes sense to use a while loop to identify whether a key is no longer being pressed :\">

  • edited February 2014

    Btw, in case you're not using the psycho back-end, here's a small code snippet that illustrates how you can accomplish approximately the same thing with the PyGame-based back-ends (legacy, expyriment, and opengl):

    import pygame
    key = None
    start_time = self.time()
    while key == None:
        time = self.time()
        for event in pygame.event.get():
            if event.type == pygame.KEYUP:
                key = event.key
    rt = time - start_time  
    print '%s was released after %d ms' % (key, rt)
    

    For more information, please see the PyGame documentation, and don't hesitate to post further questions!

    Cheers,
    Sebastiaan

  • edited 4:49AM

    Hi,

    I think this is a fantastic discussion; I have the same need for my study. I'm using sebastiaan's suggestion (for use with PyGame). However it doesn't seem to be recording the reaction time ("rt" variable). Or in fact, recording anything after the stimulus is presented. How do I get OpenSesame to record this part in logger?

    And...I'm a little uncertain how this works in the experiment workflow. Do I place this Python script after the keyboard_response item, before it, or does it entirely replace the keyboard_response item?

    Thanks,
    Adam

  • edited November 2014

    Never mind! Some more googling found me this comment, also by Sebastiaan.

    Basically, the python script needs to define the variable as well via exp.set() so there should also be a line like this:

    exp.set('keyreleaseRT', rt)

    All good now! Although I have no idea what the last print line is for, it doesn't seem to do anything.

  • edited November 2014

    HI Adam,

    All good now! Although I have no idea what the last print line is for, it doesn't seem to do anything.

    The timing for each keypress should appear there, since this is were prints usually print to.
    Anyway, good to hear that it works now for you.

    Best,

    Eduard

    Buy Me A Coffee

  • edited 4:49AM

    The timing for each keypress should appear there

    What does "there" mean? Is the screen supposed to display the print line after I release the key? I'm not sure how that works since there isn't a text_render item around that part of the loop.

    Thanks,
    Adam

  • edited 4:49AM

    Sorry! I think I rewrote my response and deleted something by accident. What "there" refers to is the debug window. If you print something, it does't appear on the screen, but the debug window.

    Sorry for the confusion.

    Eduard

    Buy Me A Coffee

  • edited 4:49AM

    Thank you, Eduard!

  • Hi,
    Sorry for resurrecting an old thread, but I was wondering if anyone had any information on how reliable the RT is using the method Andrea (Embodiment) proposed above. Would it be anywhere near millisecond accurate (ignoring issues tied to the particular keyboard itself)? Is it tied to screen refresh (the win.flip seems to suggest that, but I'm not sure)?
    Thanks,
    Mark

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