Howdy, Stranger!

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

Supported by

Keyboard Timeout set to a jitter

Hey Everyone,

Right now I am trying to implement a jitter to my experiment but I need to keyboard to timeout in response to the jitter. In order to do this, I have used inline script to set up my keyboard. Right now I get the following error: "TypeError: keyboard() takes at least 1 argument (0 given)"

from random import randint
from openexp.keyboard import keyboard

#start timer
t0 = clock.time()

#calculate jitter length
offset_time = randint(850, 1150)

#initiate keyboard, set wait time to the jitter
my_keyboard = keyboard(keylist=['space'], timeout=offset_time)
start_time = clock.time()

#get keyboard response
key, end_time = my_keyboard.get_key()
var.response = key
var.response_time = end_time - start_time

#calculate offset wait time (in case of early keypress), using the jitter
t1 = clock.time()
current = (t1-t0)
if current < offset_time:
    time = offset_time-current
    self.sleep(int(time))

Comments

  • Hi,

    The error is because you're mixing the old (≤ 2.9) and new (≥ 3.0) ways of creating a keyboard object.

    The old way is to import the keyboard function (from openexp.keyboard import keyboard), and pass exp as the first argument. You're doing the former, but not the latter.

    # <= 2.9
    from openexp.keyboard import keyboard
    k = keyboard(exp) # Plus optional keywords
    

    The new way is to not important anything, and not pass exp as first argument. So it's much cleaner.

    # >= 3.0
    k = keyboard() # Plus optional keywords
    

    Does that make sense?

    See also:

    Cheers,
    Sebastiaan

  • Sebastiaan,

    This absolutely makes sense. I removed the import and it appears to be working perfectly now. I had another problem come up though, when I try to evaluate whether or not a correct response is given, in the case where the correct response is 'None' (i.e., no keyboard response is the correct response), I can't get the program to evaluate that as a "correct response". I tried adding print lines and "correct_response" is 'None' and the response is 'None' but when I compare the values in an if-statement it evaluates as false! Any ideas?

    from random import randint
    
    #start timer
    t0 = clock.time()
    
    #calculate jitter length
    offset_time = randint(850, 1150)
    
    #initiate keyboard, set wait time to the jitter
    my_keyboard = keyboard(keylist=['space', '1'], timeout=offset_time)
    start_time = clock.time()
    
    #get keyboard response
    key, end_time = my_keyboard.get_key()
    var.response = key
    var.response_time = end_time - start_time
    
    #Set correct response
    if var.response == var.correct_response:
        correct = 1
    else:
        correct = 0
    var.correct = correct
    
    #print for debug
    print("--Trial--")
    print(var.response)
    print(var.response_time)
    print(var.correct_response)
    print(var.response == var.correct_response)
    print(var.correct)
    
    #calculate offset wait time (in case of early keypress), using the jitter
    t1 = clock.time()
    current = (t1-t0)
    if current < offset_time:
        time = offset_time-current
        self.sleep(int(time))
    
  • Hey,

    In case no response is given, your variable key, is of None type. The variables in your loop table are implicitly converted to a number or to a string (where applicable). So typing None, will eventually be converted to "None". Do you see what I mean? (If not you can print the types of your response and your correct response variable. To make it work, you can also convert your key variable to a string (e.g. var.response = unicode(key).
    Does this make sense?

    Eduard

    Buy Me A Coffee

  • Eduard,

    That absolutely makes sense and it absolutely worked. Thank you so much for your response!

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