[solved] Multi-character keyboard response *or* simultaneous sketchpad and text_input
Hello again,
I need my participants to be able to view a picture on sketchpad and then enter a multi-character keyboard response. Right now I have them viewing the sketchpad, doing a keypress to advance, and then using text_input to enter their response. I think the intermediate keypress-to-advance-to-text_input is distracting and I would like to eliminate it if possible.
The only way I see sketchpad can accept responses is by setting the duration to "keypress" (which will advance after a single keypress), or by using the keyboard response module (which also does not (seem to) allow multi-character responses). Ideally I would like the participant to be able to continue viewing the sketchpad while doing text_input, because it lets them see what they've typed and then press enter before advancing to the next step. I tried messing with the foreground of text_input but it seems to only accept colors.. I also tried telling the text_input to draw an image from a file but it doesn't like that either. Is what I'm describing possible in OpenSesame? Thanks in advance!
I need my participants to be able to view a picture on sketchpad and then enter a multi-character keyboard response. Right now I have them viewing the sketchpad, doing a keypress to advance, and then using text_input to enter their response. I think the intermediate keypress-to-advance-to-text_input is distracting and I would like to eliminate it if possible.
The only way I see sketchpad can accept responses is by setting the duration to "keypress" (which will advance after a single keypress), or by using the keyboard response module (which also does not (seem to) allow multi-character responses). Ideally I would like the participant to be able to continue viewing the sketchpad while doing text_input, because it lets them see what they've typed and then press enter before advancing to the next step. I tried messing with the foreground of text_input but it seems to only accept colors.. I also tried telling the text_input to draw an image from a file but it doesn't like that either. Is what I'm describing possible in OpenSesame? Thanks in advance!
Comments
No, I'm afraid that isn't possible without some inline coding. But fortunately nothing terribly complicated. The following code snippet accepts keyboard input until 'return' is pressed and overlays the resulting string over the canvas of a sketchpad called 'my_sketchpad' (which should be the last item prior to this piece of inline code).
I hope this will help you to get started! You can find more information about the keyboard en canvas classes here, so you can tweak this code a bit to fit your needs (text position, font sizes, etc.):
http://osdoc.cogsci.nl/python-inline-code/canvas-functions
http://osdoc.cogsci.nl/python-inline-code/keyboard-functions
Update: As of OpenSesame 0.27, using
to_chr()
is not necessary anymore.Check out SigmundAI.eu for our OpenSesame AI assistant!
This works great, thank you! For future reference, what if I wanted to change the location of the text input? Right now it's in the middle of the screen.
Nevermind, I figured it out. Putting in x- and y-coordinates is easy: my_canvas.text(resp,x=100,y=100) etc. Thanks!
Hi,
I partecipated yesterday to the workshop you made in Rovereto.
If you remember I asked you a question about my experiment, but I have some problems.
I found this code in this post very useful but not exacty what I need.
I have to do an experiment where my participants ear a word and simply write the word on the keyboard (during the sound). Using the code you suggested I can do it quite easy.
The problem is that I have to register every key press reaction time. So, if the word is “dog” I need the timing of “d”, “o” and “g”.
In the log file I see that I have a “correct column” with 0 and 1 if the word is correct. And this is perfect. But I want to record also what they write as incorrect response and mostly the reaction time for each key press.
Then, I need exactly the same experiment on a mobile phone.
Do you think it is possible? Can you kindly suggest me how to do?
Thanks!
Tania
Hi Tania,
Sure, I remember!
The
openexp.keyboard
module will, as you have noticed, show and hide the Android virtual keyboard for every keypress. If you want to bypass this limitation, you have to usepygame
directly, and show/ hide the virtual keyboard yourself. This makes the script a little more complicated, but nothing too difficult. Below you see basically the same script as above, except that it usespygame
to collect key presses and it also logs information about every individual key press. I don;t know what kind of format you prefer for your logfile, but this shows the basic idea. See the code comments for more explanation.See also:
Cheers!
Sebastiaan
Update: Fix script to work around
event.unicode
bug.Check out SigmundAI.eu for our OpenSesame AI assistant!
Thanks a lot. This code works perfectlly on my pc.
I tested it on a tablet S3 tab 10 – android 4.2.2.
the keyboards responses appear as punctuations. For example, I write "Home" and it appears ");):"...punctuations.
Furthermore, no logfile is saved.
Do you think that this is a problem of the device/android version?
Sorry to bother, I’m testing on available devices. Before bay a new one I want to be sure that it works.
Thanks again
Tania
Ow, you're right, that's due to a problem/ bug in the library that is used for Android (called pgs4a), which slipped my mind for a second. I updated the script above. (It's nothing to do with your device or Android version.)
Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Ok. Now I can use also my Nexus 5, Android version 4.4. Great! Thank you so much
The last strange problem that I have: I'm trying to run a trial of the experiment. I notice that the logfiles change occasionally...I really don't know way:
The program is able to record keypresses: the Unicode works well on the pc, not on Android. I can accept this. But sometimes every keypress is recorded and sometimes only 5 keyresses. So, if I have a word of 6 letters I cannot see the rt of the last keypress. This is very annoying. I risk to loose data. The strange thing is that it happens not all the time.
Do you have any idea?
Thank for you availability!
Sorry if I write again, any possible explanation?
I suspect that the
logger
detects only the variables that exist when the item is first called. So if you enter five characters on the first trial, you log the first five keypresses, etc. Is that it? If so, you can tell thelogger
explicitly which variables should be logged, by disabling the 'Automatically detect and log all variables' option and using 'Add custom variable' (or select variables from the list).Alternatively, you can open the general script (by clicking on 'Edit script' in the general tab) and add all variables that you want to log like so (add to the top of the script):
This is a simple trick to make OpenSesame aware that these variables exist.
Does this help at all?
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thanks Sebastian for your help. if I use the code for dummy variables, the log file give me columns without rt, but the word "dummy". however I manage to do it in another way.
By the way, I want to ask you one curiosity that ca be helpful for me: Opensesame automatically reverse the screen on my smartphone. Is it possible to mantain it straight?
Thanks a lot for halping me. Now I can start my experiment using this helful software!
Cheers
Tania
Good!
No, not at the moment. The screen orientation for the Android runtime for OpenSesame is fixed to landscape, due to a limitation in the underlying software. I might release two different apps (one for landscape, one for portrait) in the future to work around this.
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
I tried the first code Sebastian posted: I copy-pasted it in an Inline Object following the sketchpad item. I have version 2.9. Trying to run the exp, it crashes after the sketchpad item shows and accepts response, and before getting to the In-Line code item. The error message is w.r.t the line that reads: "if my_keyboard.key.to_chr=="RETURN" "; the error message reads: " 'legacy' object has no attribute 'key'' and Exception Type is Attribute Error. I tried removing to_chr, and replacing RETURN with ENTER. No luck; same message.
I want to collect multi-key response (allowable numerical, comma, backspace, and Enter to collect and terminate"; I want the response collection to happen while the sketchpad remains displayed.
I am a complete coding novice and would appreciate any help.
Hi Sebastiaan or anyone who had the similar experience,
I have the same problem with the first poster jjholiday here. Thanks to Sebastiaan's codes at the second post above and it works well. However, my question is how can I change the input language to other language (in my case, Mandarin Chinese). Even though I changed the PC language input through the right bottom button on my PC screen to Chinese (or using alt+ctr on windows), in the experiment, it still enters in English letters. I'm quite green in Python programming, can you show me how to do it?
Great thanks in advance!
@sandrazeng1987 What exactly do you want to do? In most cases, nowadays, using a form would be preferable, does not (necessarily) require Python programming, and should support Chinese input.
See here:
Do forms suit your needs?
Check out SigmundAI.eu for our OpenSesame AI assistant!
@sebastiaan
Hi, thank you for your reply. So my experiment is to show English word on the screen and ask the participants to type a Chinese translation (with Chinese input ). I tried the form item, but there are two problems here:
1) No matter I change my language input before or after I star the running of the experiment, the typing are always in English
2) Put aside my experiment, which font do I choose in the list of "font family" under the form item, in order to support the Chinese presentation? I tried many of the listed fonts which look like they are designed for Chinese characters. But the thing is in the designing interface, I can see the Chinese works perfect, but when I run the experiment, what I put in the form question turned into unrecognizable squares on the screen.
Can I ask why and whether there are ways to solve the two problems?
Thank you!
Hi Sandra,
Entering non-Latin characters is possible but not very convenient, and the details depend on your operating system. Here are a few pointers:
chinese-japanese-korean
font in the General Properties tab of the experiment.Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hello,
I'm trying to run the same experiment as Tania, it did work with latin keyboard, but I would like to do the same with an arabic keyboard.
The problem is that nothing happen when I press arabic letters on the keyboard, it's like OpenSesame doesn't get that a key is pressed (but it see the special keys in the script like space or return).
Do you have any ideas why the software does not detect arabic keypress?
(I am working on a soft keyboard on samsung tab with the droid backend.)
Thank you,
Elie
Hi Elie,
Input of non-Latin text is, as far as I know, not possible with the droid backend. In fact, I might only work correctly with QWERTY (soft) keyboards, although of that I'm not sure. This is a serious limitation, but since the droid backend is no longer developed, this will not be fixed.
A few other solutions that you could consider:
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
I can't find a way to change the fonttype and fontsize of the text that the subject is typing.
I tried inserting "my_canvas.set_font('sans', 40)" in the inline but it doesn't work. Do you have any ideas ?
Thanks a lot !
Jb.
Ok I finally find out how to do it, I just had to set it in the general experiment settings. Right know I just have a problem writting accents...
Hello,
I used Sebastiaan's script (second comment) to create a study with a multi-character keyboard response, but I need to modify it in two ways :
Could anyone help me with this ?
Thanks!
Karolina
Hi Karolina,
Without going into a lot of detail in Sebastiaan's code, you can captalize a string with the
upper
function. So if the variableresp
is the variable that you want to capitalize you can callresp = resp.upper()
to change it to upper case. For your second point, you need either some if statements, or create a mapping:1) if statement:
2) mapping
How this integrates with Sebastiaan's code I can't tell you right away. Can you figure this out yourself?
Eduard