letters generation task
Hello,
As part of my thesis, I program a sequence learning task on OpenSesame.
Sequences consist of letters F, G, H, I presented either in sequential order or randomly. To answer the participants must press the keys of the keyboard E, R, Y, U.
To determine if there is indeed a learning, I ask them to carry out after this task a task of generation of letters. from a letter displayed in the center of the screen I ask the participants to recall the following 3 letters. From the sequence following the serial order presented in the previous task. I used the inline_script item. I managed to display the letter serving as a clue on the sketchpad and then transfer it to my canvas.
The difficulty I currently have is that I would like the letters to display when I press E, R, Y or U because at the moment I can only display the letters when I press the keys keyboard F, G, H, I. I thought maybe use: my_keyboard = Keyboard(keylist=['', ''], timeout=keypress) but I have a doubt.
Anyone have an idea?
Comments
Hi @lorinap ,
It's not entirely clear to me what you want to do exactly, and it what sense it currently doesn't work as you'd like it to. However, when it comes to specifying the allowed responses, you can do this by:
keyboard_responseitem as shown here; orlistof key names to aKeyboardobject in a Pythoninline_scriptas shown here.Hope this helps!
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi sebastiaan,
Thank you for your message.
I'm sorry if my explanation was not very clear.
My experience is divided into two different tasks. In the first task the participants have to categorize the letters F, G, H, I with the keyboard keys E, R, Y, U. The stimuli are presented in a certain order. In the second task, participants must recall these letters in this specific order. To help them, a single letter serving as a clue is displayed on the screen. Participants must then complete. Using the inline_script item, I managed to get the answers to display on the screen. However, to display the stimuli you have to press the F, G, H keys. However, in order not to disturb the participants, I would like to keep the same correspondence between the letters and the keys of the keyboard as the first task.
I had tried using the keyboard_keylist function but failed. I will try your idea.
Thank you for your advice !
lorinap
Here is my programming regarding responses. By using conditional statements, I wanted to allow participants to delete their errors. I wanted for the last line to add keyboard_list but I have already defined my_keyboard.
my_keyboard = keyboard(self.experiment) resp = "" # Here we store the response while True: # Get a keyboard response key, time = my_keyboard.get_key() # keyboard.to_chr() converts the keycode to a description, # like 'space' or 'return'. If return is pressed the loop # should be exited. if my_keyboard.to_chr(key) == "return": break # Handle backspace by removing the last character if my_keyboard.to_chr(key) == "backspace": resp = resp[:-1] else: # The built-in chr() converts the keycode to a character, # like ' ' and '/'. resp += my_keyboard.to_chr(key)Hi Lorinap,
I think this should do:
kb = Keyboard() resp = "" # Here we store the response key_mapper = {'f':'e', 'g':'r', 'h':'y', 'i':'u'} while True: key, time = kb.get_key() if key == "return": break if key == "backspace": resp = resp[:-1] print(resp) else: try: resp += key_mapper[key] except KeyError: print(f"{key} is not valid") var.resp = respps, I edited your post to properly format code to make it more readable
Hi eduard,
Thank you for your message.
I didn't know that with key_mapper you could map keys to stimuli. Thanks for showing it to me. However I believe that the except KeyError part is incompatible with the display of my canvas. Here is my coding, I transfer my sketchpad on my canvas. OpenSesame gives me a problem with the first line of this coding.
What do you think ?
my_canvas.copy(self.experiment.items["my_sketchpad"].canvas)my_canvas.text(resp,x=0,y=0)
my_canvas.show()
# Save the response
self.experiment.set("response", resp)
If you want me to help you, you at least have to tell me what the error is, and provide some more context. Like that I could only guess what is happening
I corrected the error. It was necessary to remove an indent at the level of the first line of the code that I have just sent to you. However when I type on the keys, the answers are not displayed following the hint on the screen.
I believe it's related to this line :
except KeyError:
print(f"{key} is not valid")
OpenSesame considers e, r, y, u keys invalid
The KeyError is raised when the key is not present in the mapping. I thought you want paricipants to press f, g,h, or i which should then appear as e, r, y, and u. So I added each of these maps to the mapping. If you need anything else, like pressing e should present an e, you can add that map yourself, e.g.
key_mapper = {'f':'e', 'g':'r', 'h':'y', 'i':'u', 'e':'e'}but as you see that would be an 1 to 1 map and therefore a bit pointless. Generally, though, design this map such that all key strokes that you want to appear on the screen are mapped the correct way.
Does that make sense?
I understand what you mean. In my experience, the letters f, g, h, i are the stimuli while e, r, y, u are the response keys. According to your explanation, I fixed this problem by reversing what you showed me for key_mapper. However, participants must complete a series of letters from a letter (f, g, h or i) displayed on the screen. But the answers of the subjects are displayed briefly only when you press Enter to move on to the next trial, which is a problem.
I can't help you without seeing any code. I mean I could write you something that could work, but without knowing anything that would again only lack something else.
I'm sorry if I'm not very clear, I don't know the Python language very well yet. Here is the code with the changes.
from openexp.canvas import canvas my_canvas = canvas(self.experiment) kb = Keyboard() resp = "" # Here we store the response key_mapper = {'e':'f', 'r':'g', 'y':'h', 'u':'i'} while True: key, time = kb.get_key() if key == "return": break if key == "backspace": resp = resp[:-1] print(resp) else: try: resp += key_mapper[key] except KeyError: print(f"{key} is not valid") var.resp = resp my_canvas.copy(self.experiment.items["my_sketchpad"].canvas) my_canvas.text(resp,x=0,y=0) my_canvas.show() # Save the response self.experiment.set("response", resp)Do you want me to send you my start code ?
I send you the two scripts.
Yes, unless you format your code properly (the way you see it in the editor), it is better to simply share your entire experiment.
This now also presents the the typed letters onto the canvas of your sketchpad. Your problem was that you copied it on every loop iteration, therefore deleting all, previous changes.
cv = Canvas() cv.copy(items['my_sketchpad'].canvas) resp = "" # Here we store the response cv['resp'] = Text(resp) kb = Keyboard() key_mapper = {'f':'e', 'g':'r', 'h':'y', 'i':'u'} while True: cv.show() key, time = kb.get_key() if key == "return": break if key == "backspace": resp = resp[:-1] print(resp) else: try: resp += key_mapper[key] cv['resp'].text = resp except KeyError: print(f"{key} is not valid") var.resp = respEduard
Thanks for your feedback. I tested the script it seems to work. The only problem, but I don't think it comes from the script, is that the first time you press a key, the answer is not displayed immediately on the screen, so you have to press it a second time.
Indeed, that is not related to the script I think. Perhaps it seems so because the sketchpad is presented first?
I agree, I've seen this problem before in a script from a colleague of mine. Even if we put it at the end, I think it's the sketchpad display that will have a time delay.
Hi @lorinap,
Just picking up on that last bit of the thread, so I might be completely off the rails here but... you might want to check that your sketchpad has a duration of 0 ms. If you left it set on "keypress>", the task would require the participant to press a key to pass the sketchpad, and then again to register a response using the code above.
Best,
Fabrice.
Hi Fabrice,
I just saw your message. Seeing the sketchpad display lag, last night I changed the sketchpad presentation duration to 0 and it worked.
Thank you for your message.
Best,
lorinap