Howdy, Stranger!

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

Supported by

Measuring how much time a button was pressed

edited June 2016 in OpenSesame

Hello,

Is there a way to measure how much time a button was pressed?
I cannot seem to locate it in the log file.

Amihai

Comments

  • edited 9:25PM

    Hi Amihai,

    I am not completely sure what your exact problem is. Are you using a button in a form base plugin and do you want to know the total response time for the form?

    If so, I don't think that it calculates response times.

    However, you could calculate them using Python code in inline scripts. You first get the time (t0) in the run phase of an inline script directly before the form is presented. Then you present the form. Then you get the time (t1) in the run phase after the inline script. The difference (t1-t0) is your response time. This is similar to the general example in the clock functions (http://osdoc.cogsci.nl/python/clock/).

    Alternatively, you could install and use the mousetrap form plugin (general information about mousetrap: http://osdoc.cogsci.nl/devices/mouse-tracking/ , specific information about mousetrap_form https://github.com/PascalKieslich/mousetrap-os/blob/master/plugins/mousetrap_form/mousetrap_form.md). It is a modified version of the form base plugin and it calculates response times automatically. If you are not interested in the mouse-tracking data (which is the actual purpose of the plugin), you can simply uncheck the option "Save mouse-tracking data".

    Hope this answers your question - feel free to ask if not!

    Best
    Pascal

  • Dear Pascal,

    I just saw your answer to my questions (after quite a delay, sorry..).

    In my exp I am asking participants to reproduce duration times of stimuli by pressing the space button.
    Is there a way to measure the time this button was pressed? I use the logger to record response time of the keyboard response but it does not seem to measure the pressing time.

    Thanks
    Amihai

  • Or maybe anyone else has an idea how to measure how much time a button was pressed using a keyboard response?

    Amihai

  • Hi Amihai,

    I assume you are using a keyboard_response item to record the key press. This will give you the duration after which the key was pressed (in the variable response_time). However, as far as I know it will not tell you for how long the key was pressed.

    Unfortunately, I don't know much about the technical details of the keyboard Python functions - so I cannot tell you whether it is possible to determine that at all - If this is what you want to know. I think that it is not possible using OpenSesame's keyboard class. One idea I have is that you maybe could directly use a Python function from one of the backends.

    Best,

    Pascal

  • Hi Pascal,

    Thanks for the help.
    I found this thread:

    http://forum.cogsci.nl/index.php?p=/discussion/2271/measure-duration-of-key-press

    But unfortunately, I do not know python very well and cannot understand which part of the code I can use just to measure the keypress and create a variable out of it. Can you help?

    Amihai

  • Hi Amihai,

    Maybe searching the forum for "keyup" helps.

    Best,
    Jarik

  • Jarik,

    Thanks for the tip! I found this thread:

    http://forum.cogsci.nl/index.php?p=/discussion/37/solved-how-to-log-the-duration-of-a-key-press

    which looks very relevant, but I can not figure out where to put this script and how to define the key which I need to measure. Do you know?

    Amihai

  • You can copy the code in an inline item that follows a sketchpad item for example. This sketchpad item can have a duration of 0 milliseconds so it advances to your inline code immediately. You can use the sketchpad item to present instructions like "press space for 2 seconds" to the subject.

    The code logs all keys now.

    Best,
    Jarik

  • Dear Jarik,

    I did what you wrote and it workes!

    Thank you very much.

    Amihai

  • Jarik, or anyone else how can help,

    Is there a way to record which button was pressed using the inline script item?

    Amihai

  • Hi,

    Maybe you can summarize what you already accomplished and what is the code that you use? Then, it will be easier to find out what else is missing.

    Eduard

    Buy Me A Coffee

  • Eduard,

    I just noticed that I never answered your message. Sorry about that.
    I ended up using the following code in the run part of the inline script:

    import pygame
    from pygame.locals import *

    key_down_time = None
    while key_down_time == None:
    for event in pygame.event.get():
    if event.type == KEYDOWN:
    key_down_time = self.time()
    key_pressed = event.key
    break

    key_up_time = None
    while key_up_time == None:
    for event in pygame.event.get():
    if event.type == KEYUP:
    key_up_time = self.time()
    break

    key_duration = key_up_time - key_down_time
    self.experiment.set("key_duration", key_duration)
    self.experiment.set("key_pressed" , key_pressed)

    With this, I manage to log the pressing time of the key that was pressed but the actual key name is logged as a number which I need to "translate" using an ASCII table. I was wondering whether it is possible to just log the name of the key.

    Thanks
    Amihai

  • Hi Amihai,

    Good to know it works.

    I was wondering whether it is possible to just log the name of the key.

    Maybe this discussion helps: https://stackoverflow.com/questions/227459/ascii-value-of-a-character-in-python

    Buy Me A Coffee

  • Eduard,

    Thanks for the link. I understand that I can use the chr() function to return the key but I do not know how to implement it in the code.
    Do you think this will this work (I do not know how to code in python):

    self.experiment.set("key_pressed" , chr(key_pressed))

    Amihai

  • That is exactly how it works.

    Eduard

    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