Howdy, Stranger!

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

Supported by

[open] getting keyboard_response to accept double digit responses

edited December 2013 in OpenSesame

as the title says, i'm trying to get the keyboard_response function to accept 2 digits rather than skipping forward after a single key press. Probably not a complex question... any advice?

Comments

  • edited December 2013

    This is generally not something you can do with a keyboard response (unless you put two of them directly after eachother, but I have the feeling this is not what you would want). You can do two things:

    1) Use the form_text_input plugin, which allows users to type their response in.

    2) Use a bit of inline scripting, like the snippet below (replace your keyboard_response with an inline_script and put the code in its Run Phase to test it).

    # first, we import the classes that we need for our script
    from openexp.canvas import canvas
    from openexp.keyboard import keyboard
    
    # then, we use these classes to create objects that we
    # are going to use in our script: first the canvas object,
    # which we will use to display stuff on the screen
    my_canvas = canvas(exp)
    # second the keyboard object, which we will use to
    # register keypresses
    my_keyboard = keyboard(exp)
    
    # now, we will need to pre-define some stuff; in this case
    # we will need the allowed numbers:
    numbers = ['0','1','2','3','4','5','6','7','8','9']
    # and an empty string, in which we are going to store the
    # response that was given by the participant
    numstring = ''
    # also, we will need to define the maximal amount of
    # numbers that can be put in
    maxlength = 2
    
    # now, before we start, let's clear the display and get the
    # starting time (useful for calculating the RT later on!)
    my_canvas.clear()
    t0 = my_canvas.show()
    
    # now, we are going to make sure the display stays on
    # until the participant presses the space button; we will
    # do so using a while loop, which runs until the 'sentry
    # variable' (in this case it's 'keeprunning') will go False
    keeprunning = True
    while keeprunning:
    
        # check if there is any keyboard input
        key, presstime = my_keyboard.get_key()
    
        # check if the input is a number
        if key in numbers:
            # then check if the number string we have is not
            # too long
            if len(numstring) < maxlength:
                # then add the number to the string!
                numstring += key
    
        # if the input was not a string, check if it was backspace
        elif key == 'backspace':
            # if it was backspace, remove the last number from
            # the string that contains the response
            numstring.pop(-1)
    
        # finally, if the input was not a string and not a number,
        # check if it was space
        elif key == 'space':
            # if it was, we can stop the loop
            keeprunning = False
    
        # now that we have the input, we need to show it to
        # the participant; first we clear the canvas, so the
        # previous contents is removed
        my_canvas.clear()
        # then we draw the current number
        my_canvas.text(numstring)
        # and we show the canvas, updating the display
        my_canvas.show()
    
    # after running the loop, set some variables to store the
    # response and the response time
    exp.set("response", numstring)
    exp.set("response_time", resptime - t0)
    
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