Howdy, Stranger!

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

Supported by

[solved] Question on mouse response with inline script

edited November 2013 in OpenSesame

Hi all!

In an old thread (http://www.cogsci.nl/forum/index.php?p=/discussion/143/open-how-do-i-collect-the-keyboard_response-after-a-stimulus-disappears/p1) I found this really nice piece of code, which enables measuring keyboard response time from the onset of a stimulus.

This is exactly what I need for my experiment and it works perfectly, but I would like to use a mouse response, instead of a keyboard response. I tried to change the code, but I was not able to do so :/

Precisely, I do not know how this command should be for the mouse response:

resp, time = my_keyboard.get_key(timeout=timeout)

and also this part of the code:

response = my_keyboard.to_chr(resp)

Sorry, if this is naive (I am not very experienced in programming and do not understand everything in the documentation), but I did not find the to_chr() function in either the keyboard or mouse response documentation, what does it even do?

Best regards,
Martin

Comments

  • edited 11:14PM

    Hi Martin,

    This is exactly what I need for my experiment and it works perfectly, but I would like to use a mouse response, instead of a keyboard response.

    The equivalent of get_key() for mouse objects is get_click().

    from openexp.mouse import mouse
    my_mouse = mouse(exp)
    resp, position, time = my_mouse.get_click(timeout=timeout)
    


    Sorry, if this is naive (I am not very experienced in programming and do not understand everything in the documentation), but I did not find the to_chr() function in either the keyboard or mouse response documentation, what does it even do?

    In older versions of OpenSesame, get_key() returned an ASCII key code, and you had to use to_chr() to convert this code to a character. Nowadays, get_key() returns a unicode representation of the key, so to_chr() is no longer needed. It's still there to avoid breaking old experiments, but it doesn't do anything.

    Hope this clears things up!

    Sebastiaan

  • edited October 2013

    Hi Sebastiaan,

    thanks for your quick reply. I get that the get_click() function is the equivalent to the get_key() function. I fear I still do not understand how this line

    response = my_keyboard.to_chr(resp) 
    

    should be for my mouse_response code. The response object should simply save which mouse button was pressed. I tried some commands, but none of them worked.

    EDIT: I tried this command:

    response = my_mouse(resp)
    

    but it gave me this error: xpyriment instance has no call method

    EDIT 2: This command:

    response = my_mouse.get_click(resp)
    

    gave me the error argument of type 'int' is not iterable

    Thanks again in advance! Best regards,

    Martin

  • edited 11:14PM

    Hi Martin

    get_click() doesn't return a single value, but a so-called tuple, which is a set of variables. You have to 'unpack' this tuple into a response, a position, and a time variable. For example, like so:

    resp, position, time = my_mouse.get_click(timeout=timeout)
    

    or like so

    my_tuple = my_mouse.get_click(timeout=timeout)
    resp = my_tuple[0]
    position = my_tuple[1]
    time = my_tuple[2]
    

    Tuples are part of the basic Python syntax. I would recommend walking through one of the entry-level Python tutorials, such A Byte of Python.

    Cheers!
    Sebastiaan

  • edited 11:14PM

    Hi Sebastiaan,

    thanks again for your reply! You are right, I really should redo some of the basic Python syntax, this will probably help me a lot. I just wanted to say that even without expert programming skills, I am now working on the third experiment in only the few weeks since I have found OpenSesame, thanks to the excellent software and your helpfulness in this forum :)

    I just seem to have a hard time with mouse responses. I have not been able to save the button which was clicked into a variable in the logger. It does not work with inline script (that was why I was asking above) and also with simple mouse response items.

    I just created a new experiment, in which I only created a sketchpad, a mouse response and a logger item. I enabled every variable that was accociated with the mouse response to be logged. None of these variables saved which button was clicked. The variable 'response' only gave the output undefined (it was None when I used an inline script). Is this a bug in my OpenSesame version? I am using Windows 7 and the latest stable OpenSesame version. I really feel stupid about the mouse response problems that I am having :/

    Thanks again, Martin!

  • edited 11:14PM

    Hi Martin,

    Could you perhaps upload your experimental script, for example to pastebin?

    Cheers,
    Sebastiaan

  • edited 11:14PM

    Hi Sebastiaan,

    you can find the test experiment here: http://pastebin.com/UgLVfYHX

    I just tried using a different mouse, but the experiment never saves the click that has been made into the logger.

    Greetings, Martin

  • edited 11:14PM

    Hi Martin,

    For me, your experiment works fine. You should see the mouse response in the following columns:

    • response and response_mouse_response
    • cursor_x
    • cursor_y
    • response_time and response_time_mouse_response

    The response should be 1, 2, or 3, for respectively the left, middle, and right button.

    If you don't see this, something is pretty wrong. What version of OpenSesame and what operating system are you using?

    Cheers,
    Sebastiaan

  • edited November 2013

    Hi Sebastiaan,

    I now see my problem: I used a variable correct_response in the experimental loop, in which I labled the possible correct answers as 'left_button' and 'right_button', don't ask me why, I am not sure. The thing is, this actually worked! I got correct responses (=1) in my correct variable when I answered correctly and incorrect responses when I answered incorrectly. I now realized, however, that the response_mouse_response variable does not save 'left_button' or 'right_button' as output, but '1' and '3'.

    The problem is probably that I am building the experiments on the computer, on which they will be running and I do not have much software on it. So, most often I look into into the data output using a simple text editor, which is not convenient. I was only looking for the output 'right_ or left_button' and not for '1' or '3'.

    Thank you and sorry for the trouble, my mistake. Btw now everything works for me =)

    With best regards,

    Martin

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