How to set "left Ctrl" and "right Ctrl" as correct response in the allowable box?

1,141 views
Skip to first unread message

Sophy Yu

unread,
Mar 29, 2015, 2:13:10 PM3/29/15
to e-p...@googlegroups.com
It doesn't let me put {Ctrl}, when I put in the attribute list, it says replicated value.

Paul Groot

unread,
Mar 30, 2015, 3:28:57 AM3/30/15
to e-p...@googlegroups.com
The {key} nomenclature topic in E-Basic help says it should be {CONTROL}

Paul

On 29 March 2015 at 20:13, Sophy Yu <sophy...@gmail.com> wrote:
It doesn't let me put {Ctrl}, when I put in the attribute list, it says replicated value.

--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To unsubscribe from this group and stop receiving emails from it, send an email to e-prime+u...@googlegroups.com.
To post to this group, send email to e-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/e-prime/d315a76c-92b7-4bad-953b-339131fb7078%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sophy Yu

unread,
Mar 30, 2015, 3:57:28 PM3/30/15
to e-p...@googlegroups.com
Thank you so much Paul! I'm very thankful for your help! However, the manual says that left or right Ctrl/SHIFT/ALT keys cannot be specified within the E-Studio GUI, need to use InLine script. I know very little about programming, wonder if you know any existing script dealing with this issue. Any advice would be greatly appreciated!

Paul Groot

unread,
Mar 31, 2015, 3:52:57 PM3/31/15
to e-p...@googlegroups.com
I don't think that will be possible using the builtin keyboard drivers of EPrime. You could use a low level windows function in an inline script to retrieve the key state of the left and right control keys: GetKeyState or GetAsyncKeyState. The latter one can be used to determine if a specific key was pressed during a specific time frame.

To be able to use this function, you should add a declaration to the global user script section:

Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal nVirtKey As Long) As Integer
Const VK_LCONTROL& = &HA2
Const VK_RCONTROL& = &HA3 

Then, add the following inline just before the stimulus/response object:

Dim dummy As Integer
dummy = GetAsyncKeyState(VK_LCONTROL)
dummy = GetAsyncKeyState(VK_RCONTROL)


And the following after the stimulus/response object:

If GetAsyncKeyState(VK_LCONTROL)<>0 Then
ShowKey.Text = "LEFT"
ElseIf GetAsyncKeyState(VK_RCONTROL)<>0 Then
ShowKey.Text = "RIGHT"
Else
ShowKey.Text = "NONE"
End If

Make sure that the stimulus/response object has the prerelease time set to zero and the allowable mask to {CONTROL}.
You will have to change the lines that set the text of the ShowKey object. This example code just sets a feedback text for demonstration purposes.


Also see the attached example script.

BVest,
Paul




GetControlKey.es2

Sophy Yu

unread,
Apr 2, 2015, 11:42:05 AM4/2/15
to e-p...@googlegroups.com

Thank you again Paul! This works just like you said! I am having trouble setting the key to correct response (e.g., LCONTROL to X, RCONTRL to U), I'm not very good with inline code, and it doesn't allow me to put in the attribute list.

Paul Groot

unread,
Apr 3, 2015, 11:24:58 AM4/3/15
to e-p...@googlegroups.com
Not sure if I understand what you mean. Which key's would you like to use: left and right control keys, or U and X? In the later case you don't need any inline script. However, when using the control key's, you should add a few lines of code to determine if the response was correct. You will probably add an attribute to the trial list  for specifying the correct response. You could use L and R for example. Then you need to add something like in the CheckLR part after the stimulus:


Dim acc As Integer
Dim corr As String
corr = c.GetAttrib("Correct")

If GetAsyncKeyState(VK_LCONTROL)<>0 Then
acc = strcomp(corr,"L",1)
ElseIf GetAsyncKeyState(VK_RCONTROL)<>0 Then
acc = strcomp(corr,"R",1)
Else
acc = -1  ' no response is -1, 0, or 1 ?
End If

c.SetAttrib "ACC", CStr(acc)
ShowKey.Text = "accuracy: " & CStr(acc)


Note that you should still determine what the acc value should be if there was no repsonse.
(Attached file was created with new EP2 SP2)

Best,
Paul



GetControlKey.es2

Sophy Yu

unread,
Apr 4, 2015, 9:15:13 PM4/4/15
to e-p...@googlegroups.com
Thank you Paul for your detailed reply! Sorry for not being clear with my question,  I mean use left/right control key as response. For example, correct response for letter X is Left CONTROL, and correct response for U is Right CONTROL(the image attached above is the experiment I'm coding).

I tried your script, put L, R in the attribute list, then letter "L"and "R" become the response key instead of CONTROL key. I didn't expect this key can be so complicated :(

Paul Groot

unread,
Apr 6, 2015, 6:17:22 AM4/6/15
to e-p...@googlegroups.com
In the example script, L and R are arbitrary and do NOT refer to any key on teh keyboard. The values are only used to specify correct Left or Right responses. This is handled in the script (left ctrl compares to 'L' and right ctrl compares to 'R'). With regular keys (such as U and X on the keyboard) this is extremely simple to do without scripting, but since you are using the two ctrl keys it becomes rather complicated because windows normally treats those two keys as being identical. The same is true for the shift keys.

Best,
Paul

Sophy Yu

unread,
Apr 7, 2015, 5:37:28 PM4/7/15
to e-p...@googlegroups.com
Thank you so much for the explanation Paul! I think I will go with a regular key. Although this doesn't work out, it's a great learning experience, thanks again!!
Reply all
Reply to author
Forward
0 new messages