Keyboard Timeout set to a jitter
in OpenSesame
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
keyboardobject.The old way is to import the
keyboardfunction (from openexp.keyboard import keyboard), and passexpas the first argument. You're doing the former, but not the latter.The new way is to not important anything, and not pass
expas first argument. So it's much cleaner.Does that make sense?
See also:
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
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?
Hey,
In case no response is given, your variable
key, is ofNonetype. The variables in yourloop tableare implicitly converted to a number or to a string (where applicable). So typingNone, 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
Eduard,
That absolutely makes sense and it absolutely worked. Thank you so much for your response!