How to capture response from keyboard?


Author
Message
kulajw
kulajw
Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)
Group: Forum Members
Posts: 51, Visits: 256
Hi everyone,

I have some problems with capturing responses from keyboard.

I would like to create procedure when sequence of letters (random length) will be presented on the screen.
The participants must remember last letter and enter it from keyboard after letter presentation.

I figure out that I can capture last presented stimuli (letter) by refering to text.text_name.currentitem
e.g. text name in my case is "letter". Letter text element is used to present sequence of letters in trial letter presentation.

When I capture last presented letter then I can compare it with participant current response by refering to trial.trial_name.response
and using   iscorrectresponse  attribute:
iscorrectresponse = [trial.trial_name.response==text.text name.currentitem]

BUT the problem is that instead of letter pressed by participant trial.trial_name.response return letter scancode and conditional statement
trial.trial name.response==text.text_name.currentitem is always evalueted as FALSE because trial.trial name.response return scancode e.g. 30 instead of "A" and text.text_name.curentitem return last presented letter as a string "A"

The question is how can I convert scancode to a string values  or waht to do in this case?

I paste my script below

Thanks for any help:)

<item letters>
/1="A"
/2="B"
/3="X"
/4="Z"
</item>

<text letters>
/items = letters
</text>


<text test>
/items = ("remember the last letter in sequence
 by pressing appropriate key on keyboard")
</text>

<trial letter_presentation>
/stimulustimes = [0=letters]
/timeout=1000
</trial>

<trial test>
/stimulustimes = [0=test]
/timeout=10000
/iscorrectresponse = [trial.test.response==text.letters.currentitem]
/validrespon
/correctmessage = (good,800)
/errormessage = (error,800)
</trial>

<block letter_block>
/trials = [1-2=letter_presentation;3=test]
</block>

<text good>
/items = ("good")
</text>

<text error>
/items = ("Error")
</text>

Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
You either need to construct a lookup table that maps scan codes back to letters or -- the easier option -- use an <openended> element to collect the response instead of a regular <trial> element.

kulajw
kulajw
Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)
Group: Forum Members
Posts: 51, Visits: 256
Hi, 

Thank you for response :)  

Do you think script below will be fine?



<item alphabet>
/1="A"
/2="B"
/3="C"
/4="D"
/5="E"
/6="F"
/7="G"
/8="H"
/9="I"
/10="J"
/11="K"
/12="L"
/13="M"
/14="N"
/15="O"
/16="P"
/17="Q"
/18="R"
/19="S"
/20="T"
/21="U"
/22="V"
/23="W"
/24="X"
/25="Y"
/26="Z"
</item>

<list scancodes>
/items = (30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44)
/selectionmode = text.letter.currentindex
</list>

<text letter>
/items = alphabet
/select = noreplace
</text>

<trial letter_presentation>
/stimulustimes = [0=letter]
/timeout = 1000
</trial>

<trial test>
/stimulustimes = [0=test]
/timeout = 10000
/correctmessage = (good,1000)
/errormessage = (error,1000)
/validresponse= (anyresponse)
/iscorrectresponse = [trial.test.response==list.scancodes.nextvalue]
</trial>

<block blok>
/trials = [1=letter_presentation;2=letter_presentation;3=test]
</block>

<text test>
/ items = ("Second letter, Please")
</text>
<text good>
/items = ("good")
/position = (30,30)
</text>

<text error>
/items = ("error")
/position = (30,30)
</text>

Dave
Dave
Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)Supreme Being (1M reputation)
Group: Administrators
Posts: 13K, Visits: 104K
It should be fine *as long as* an English keyboard layout is used. On some other layouts certain keys are in different locations, i.e., the letter - scancode mapping is different and your lookup table is not applicable.

Consider first the standard English QWERTY layout:
Y maps to scancode 21 and
Z maps to scancode 44.
Consider by contrast the German keyboard layout, called QWERTZ, which has the Z and Y keys switched compared to the English QWERTY. Here
Y maps to scancode 44 and
Z maps to scancode 21.
The French keyboard layout is AZERTY, i.e., whereas on the English and German layouts
Q maps to scancode 16, it is
A that maps to scancode 16 on a French keyboard.

Whether that poses a problem for you depends on how you plan to collect data / whether it's a scenario where you are likely to encounter non-English keyboard layouts (obviously, it can't happen in a lab environment, where the computers used are under your control).

Using <openended> as indicated previously would avoid the scancode issue.

kulajw
kulajw
Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)Guru (5.9K reputation)
Group: Forum Members
Posts: 51, Visits: 256
Thank you for response,


I did not know that scan codes work differently in different keyboard layouts.
It is a nice lesson and will help me to avoid some errors in future.
Thank you :)


So  it seems that using <openended> is definitely better solution in this case.




GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Explore
Messages
Mentions
Search