Millisecond Forums

Questions Approach-Avoidance Task: keypress

https://forums.millisecond.com/Topic26524.aspx

By charlotte.w - 3/5/2019

Hi,

is it possible to combine the AAT with keypress as response device instead of the joystick or mouse? And if so, how can I ensure that the keypress is linked to the zoom effect such that if the key is pressed, the picture increases/decreases and if the key press is stopped the movement of the Picture is also stopped?

Best
Charlotte
By Dave - 3/5/2019

charlotte.w - Tuesday, March 5, 2019
Hi,

is it possible to combine the AAT with keypress as response device instead of the joystick or mouse? And if so, how can I ensure that the keypress is linked to the zoom effect such that if the key is pressed, the picture increases/decreases and if the key press is stopped the movement of the Picture is also stopped?

Best
Charlotte

It's possible, but you'll have to make some extensive modifications to the script. When a given key is pressed, you'll want to start the zoom in or zoom out sequence, depending on which key was pressed. You'll have to decide on some fixed time and size change for each zoom step, and those <trial> elements ought to be set up to detect a key release and then stop the sequence accordingly. When you're working with a regular keyboard, keys are identified by their respective keyboard scan code (see Tools -> Keyboard Scancodes...). A key release is specified by prepending a minus sign to the respective scan code, i.e.

<trial press>
...
/ validresponse = (57)
</trial>

would detect a press on the space bar, while

<trial release>
...
/ validresponse = (-57)
</trial>

would detect the space bar's release.
By charlotte.w - 3/7/2019

Dave - Tuesday, March 5, 2019
charlotte.w - Tuesday, March 5, 2019
Hi,

is it possible to combine the AAT with keypress as response device instead of the joystick or mouse? And if so, how can I ensure that the keypress is linked to the zoom effect such that if the key is pressed, the picture increases/decreases and if the key press is stopped the movement of the Picture is also stopped?

Best
Charlotte

It's possible, but you'll have to make some extensive modifications to the script. When a given key is pressed, you'll want to start the zoom in or zoom out sequence, depending on which key was pressed. You'll have to decide on some fixed time and size change for each zoom step, and those <trial> elements ought to be set up to detect a key release and then stop the sequence accordingly. When you're working with a regular keyboard, keys are identified by their respective keyboard scan code (see Tools -> Keyboard Scancodes...). A key release is specified by prepending a minus sign to the respective scan code, i.e.

<trial press>
...
/ validresponse = (57)
</trial>

would detect a press on the space bar, while

<trial release>
...
/ validresponse = (-57)
</trial>

would detect the space bar's release.

Hi Dave,

thanks for your reply. Probably, the following code would have to be changed?
<trial AAT_4>
/inputdevice = mouse
/ ontrialbegin = [values.selectstimulus = list.category4.nextvalue]
/ ontrialbegin = [values.targetcategory = 2; values.targetformat = "p"]
/ ontrialbegin = [picture.targetstimulus.height = values.startheight_B]

/ ontrialbegin = [values.starttime = script.elapsedtime; values.endtime = 0]
/ ontrialbegin = [values.completeRT = 0; values.changedirection = 0; values.finalresponse=""]

/ stimulusframes = [1 = targetstimulus]
/ validresponse = (mousemove)
/isvalidresponse = [(trial.AAT_4.responsey > (values.mouse_y + values.pixeltolerance)) ||
(trial.AAT_4.responsey < (values.mouse_y - values.pixeltolerance)) ]
/ iscorrectresponse = [(values.expcondition == 1 && trial.AAT_4.responsey > values.mouse_y) ||
(values.expcondition == 2 && trial.AAT_4.responsey < values.mouse_y)]

/ errormessage = true(error,500)
/ontrialend = [if (trial.AAT_4.responsey < values.mouse_y) values.response = 1 else values.response = 2]
/ ontrialend = [values.mouse_change = abs(values.mouse_y - trial.AAT_4.responsey)]
/ ontrialend = [values.mouse_y = trial.AAT_4.responsey]

/ ontrialend = [if (trial.AAT_4.correct) values.sumRTcorrect_4 += trial.AAT_4.latency]
/ ontrialend = [values.sumRT_4 += trial.AAT_4.latency]

/ ontrialend = [values.trialcode = "AAT_4"]
/ ontrialend = [values.RT = trial.AAT_4.latency]
/ ontrialend = [values.correct = trial.AAT_4.correct]
/ ontrialend = [values.stimulus = picture.targetstimulus.currentitem]

/ontrialend = [if (values.response == 1) values.initialresponse = "PUSH"
else values.initialresponse = "PULL"]

/ branch = [if (values.response == 1) trial.decrease else trial.increase]
/recorddata = false
</trial>

And for the change of picture size:
<trial decrease>
/inputdevice = mouse
/ ontrialbegin = [picture.targetstimulus.height = picture.targetstimulus.height - values.mouse_change/(values.maxheight/2) * expressions.maxheightchange_px]

/ stimulusframes = [1 = eraser, targetstimulus]
/validresponse = (mousemove)
/ontrialend = [values.mouse_change = abs(values.mouse_y - trial.decrease.responsey)]

/ontrialend = [trial.decrease.resetstimulusframes()]

/branch = [if (script.subjectid == "monkey") {values.endtime = script.elapsedtime; values.finalresponse = "PUSH"; trial.intertrialinterval}]

/branch = [if (trial.decrease.responsey <= 1)
{if( 1 == values.targetcategory) {values.mouse_y = trial.decrease.responsey; values.endtime = script.elapsedtime; values.finalresponse = "PUSH"; trial.enddecrease} else { trial.maxdecrease }}]
/branch = [if (trial.decrease.responsey <= values.mouse_y)
{values.mouse_y = trial.decrease.responsey; trial.decrease}]
/branch = [if (trial.decrease.responsey > values.mouse_y)
{values.mouse_y = trial.decrease.responsey; values.changedirection += 1; trial.increase}]

/ recorddata = false
</trial>

<trial maxdecrease>
/inputdevice = mouse
/ontrialbegin = [picture.targetstimulus.height = picture.targetstimulus.height + values.mouse_change/(values.maxheight/2) * expressions.maxheightchange_px]
/stimulusframes = [1 = targetstimulus, hint_please_pull]
/validresponse = (mousemove)
/isvalidresponse = [trial.maxdecrease.responsey > values.mouse_y]
/ontrialend = [values.mouse_change = abs(values.mouse_y - trial.maxdecrease.responsey); values.mouse_y = trial.maxdecrease.responsey; trial.maxdecrease.resetstimulusframes()]
/branch = [trial.increase]
/recorddata = false
</trial>

<trial enddecrease>
/ontrialbegin = [picture.targetstimulus.height = picture.targetstimulus.height - values.mouse_change/(values.maxheight/2) * expressions.maxheightchange_px]
/stimulusframes = [1 = eraser, targetstimulus]
/timeout = 0
/branch = [trial.intertrialinterval]
/recorddata = false
</trial>

But I have no idea how this could be changed according to key press. How would you combine the key press with the size of the picture? Duration of key press?

Best
Charlotte
By Dave - 3/8/2019

charlotte.w - Friday, March 8, 2019
Dave - Tuesday, March 5, 2019
charlotte.w - Tuesday, March 5, 2019
Hi,

is it possible to combine the AAT with keypress as response device instead of the joystick or mouse? And if so, how can I ensure that the keypress is linked to the zoom effect such that if the key is pressed, the picture increases/decreases and if the key press is stopped the movement of the Picture is also stopped?

Best
Charlotte

It's possible, but you'll have to make some extensive modifications to the script. When a given key is pressed, you'll want to start the zoom in or zoom out sequence, depending on which key was pressed. You'll have to decide on some fixed time and size change for each zoom step, and those <trial> elements ought to be set up to detect a key release and then stop the sequence accordingly. When you're working with a regular keyboard, keys are identified by their respective keyboard scan code (see Tools -> Keyboard Scancodes...). A key release is specified by prepending a minus sign to the respective scan code, i.e.

<trial press>
...
/ validresponse = (57)
</trial>

would detect a press on the space bar, while

<trial release>
...
/ validresponse = (-57)
</trial>

would detect the space bar's release.

Hi Dave,

thanks for your reply. Probably, the following code would have to be changed?
<trial AAT_4>
/inputdevice = mouse
/ ontrialbegin = [values.selectstimulus = list.category4.nextvalue]
/ ontrialbegin = [values.targetcategory = 2; values.targetformat = "p"]
/ ontrialbegin = [picture.targetstimulus.height = values.startheight_B]

/ ontrialbegin = [values.starttime = script.elapsedtime; values.endtime = 0]
/ ontrialbegin = [values.completeRT = 0; values.changedirection = 0; values.finalresponse=""]

/ stimulusframes = [1 = targetstimulus]
/ validresponse = (mousemove)
/isvalidresponse = [(trial.AAT_4.responsey > (values.mouse_y + values.pixeltolerance)) ||
(trial.AAT_4.responsey < (values.mouse_y - values.pixeltolerance)) ]
/ iscorrectresponse = [(values.expcondition == 1 && trial.AAT_4.responsey > values.mouse_y) ||
(values.expcondition == 2 && trial.AAT_4.responsey < values.mouse_y)]

/ errormessage = true(error,500)
/ontrialend = [if (trial.AAT_4.responsey < values.mouse_y) values.response = 1 else values.response = 2]
/ ontrialend = [values.mouse_change = abs(values.mouse_y - trial.AAT_4.responsey)]
/ ontrialend = [values.mouse_y = trial.AAT_4.responsey]

/ ontrialend = [if (trial.AAT_4.correct) values.sumRTcorrect_4 += trial.AAT_4.latency]
/ ontrialend = [values.sumRT_4 += trial.AAT_4.latency]

/ ontrialend = [values.trialcode = "AAT_4"]
/ ontrialend = [values.RT = trial.AAT_4.latency]
/ ontrialend = [values.correct = trial.AAT_4.correct]
/ ontrialend = [values.stimulus = picture.targetstimulus.currentitem]

/ontrialend = [if (values.response == 1) values.initialresponse = "PUSH"
else values.initialresponse = "PULL"]

/ branch = [if (values.response == 1) trial.decrease else trial.increase]
/recorddata = false
</trial>

And for the change of picture size:
<trial decrease>
/inputdevice = mouse
/ ontrialbegin = [picture.targetstimulus.height = picture.targetstimulus.height - values.mouse_change/(values.maxheight/2) * expressions.maxheightchange_px]

/ stimulusframes = [1 = eraser, targetstimulus]
/validresponse = (mousemove)
/ontrialend = [values.mouse_change = abs(values.mouse_y - trial.decrease.responsey)]

/ontrialend = [trial.decrease.resetstimulusframes()]

/branch = [if (script.subjectid == "monkey") {values.endtime = script.elapsedtime; values.finalresponse = "PUSH"; trial.intertrialinterval}]

/branch = [if (trial.decrease.responsey <= 1)
{if( 1 == values.targetcategory) {values.mouse_y = trial.decrease.responsey; values.endtime = script.elapsedtime; values.finalresponse = "PUSH"; trial.enddecrease} else { trial.maxdecrease }}]
/branch = [if (trial.decrease.responsey <= values.mouse_y)
{values.mouse_y = trial.decrease.responsey; trial.decrease}]
/branch = [if (trial.decrease.responsey > values.mouse_y)
{values.mouse_y = trial.decrease.responsey; values.changedirection += 1; trial.increase}]

/ recorddata = false
</trial>

<trial maxdecrease>
/inputdevice = mouse
/ontrialbegin = [picture.targetstimulus.height = picture.targetstimulus.height + values.mouse_change/(values.maxheight/2) * expressions.maxheightchange_px]
/stimulusframes = [1 = targetstimulus, hint_please_pull]
/validresponse = (mousemove)
/isvalidresponse = [trial.maxdecrease.responsey > values.mouse_y]
/ontrialend = [values.mouse_change = abs(values.mouse_y - trial.maxdecrease.responsey); values.mouse_y = trial.maxdecrease.responsey; trial.maxdecrease.resetstimulusframes()]
/branch = [trial.increase]
/recorddata = false
</trial>

<trial enddecrease>
/ontrialbegin = [picture.targetstimulus.height = picture.targetstimulus.height - values.mouse_change/(values.maxheight/2) * expressions.maxheightchange_px]
/stimulusframes = [1 = eraser, targetstimulus]
/timeout = 0
/branch = [trial.intertrialinterval]
/recorddata = false
</trial>

But I have no idea how this could be changed according to key press. How would you combine the key press with the size of the picture? Duration of key press?

Best
Charlotte

From the trial that takes the intitial key press, you need to /branch to the trial that increases or decreases size respectively.

Those latter trials, you need to give a fixed duration and each instance of that trial needs to in- or decrease the size by a fixed amount you need to decide on.

Those trials you need to set up to detect key releases. If no response / no release is detected in those trials, they ought to just keep /branch'ing to themselves until the maximum (or minimum, respectively) size is reached.