How to get the first keypress and ignore others?

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
ThierryO
Posts: 7
Joined: Thu Mar 13, 2008 11:35 am

How to get the first keypress and ignore others?

Post by ThierryO » Mon Mar 17, 2008 3:56 pm

Hello everybody,

I'm developing a stack for psychology research (for sholars: the pro- and anti-saccade task). Here is the task: individuals look at a cross on the middle of the screen, then ignore or not a square that is presented at left or right of the cross. After a few milliseconds, the square disapears, and an arrow is displayed, again at left or right of the cross. The arrow is either oriented left, right or top. As quickly as possible, subjects have to press on the arrowkeys to indicate orientation of the arrow on the screen. There are several trials like this.

My problem is that, if subjects press twice (or more) on one arrowkey, the first keypress is considered as the subject's reply for the current trial, but the other keypresses are memorized and used for the next trials.

What I want to do is, for each trial, to take into account the first keypress only (and ignore the others).

Any help wil be helpful, as the expriment is expected to begin in the next days!

tx in advance,
Thierry

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5132
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Mar 19, 2008 11:53 am

Last edited by Mark on Wed Mar 19, 2008 1:51 pm, edited 1 time in total.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5132
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Mar 19, 2008 11:54 am

Hi Thierry,

Why do your test subjects press the arrow key twice? I bet your application isn't responsive enough. If you let them hear a beep, (or a more sympathetic sound if possible), when they press they arrow key, they know the computer is processing their answer.

Additionally, you can log the moment when the arrow key was pressed:

Code: Select all

local lTime
local lUserAttempts

on arrowKey theDirection
  if not (lTime is an integer) then put 0 into lTime
  if not (lUserAttempts is an integer) then put 0 into lUserAttempts
  beep
  if the millisecs - lTime > 250 then
    put the millisecs into lTime
    - - hide and show pictures here
  else
    -- want to know how many times the
    -- arrowkey got hit while it shouldn't?
    add 1 to lUserAttempts
  end if
end arrowKey
Best,

Mark
Last edited by Mark on Wed Mar 19, 2008 1:51 pm, edited 1 time in total.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

ThierryO
Posts: 7
Joined: Thu Mar 13, 2008 11:35 am

Post by ThierryO » Wed Mar 19, 2008 1:14 pm

hi Mark,

Thank you for your reply.
normally, subjects only should press once. But my concern is that sometimes they might want to correct their response. So, even if instructions indicate this is not possible, or even if there is a beep as you suggested, I prefer to anticipate the problem by scripting the stack to prevent such double press.

I'am sorry but I don't undestand how your script prevent the stack to react to a second keypress.
it is perhaps best to show you my script. Here it is but simplified for posting:


global gCheckResponse,gLog,gDebut,gCueTime,gTargetTime,gMinFix,gMaxFix,gBloc1
local TpRep

on opencard
put "no" into gCheckResponse -- variable for checking when to record an arrowkey press
Presentation
end opencard

on Presentation
show field "FixationField" -- fixation point
wait (gMinFix + random(gMaxFix)) milliseconds
hide field "FixationField"
show graphic "Cue..." -- show the square at left or right for cueing the arrow position
wait gCueTime milliseconds
hide graphic "Cue..."
.... here some lines for selecting on which side, and which arrow is displayed, then...
put the milliseconds into gdebut
show field "x" -- display arrow
put "yes" into gCheckResponse -- ready to collect subject's response
wait 150 milliseconds
hide field x"
end Presentation

on arrowkey thekey
put the milliseconds into TpRep
if gAttente is "yes" then --check if record subject's response
put "no" into gCheckResponse
put thekey & coma & (gDebut - TpRep) & return after gLog....
Presentation
end if
end arrowkey

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5132
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Wed Mar 19, 2008 2:09 pm

Hi Thierry,

Looking at your scripts, I believe I am right, saying that your programme is irresponsive. The wait commands make it irresponsive to any user input. If, for whatever reason, the user presses the arrowKey while your programme is waiting, the user has a valid reason to press the arrowKey again, and again and...

Try to avoid the wait commands, use "send in x millisecs" instead. This probably means cutting your handler into smaller pieces.

The script I posted the nothing more than ignoring arrowKeys if the user pressed an arrowkey less than .25 seconds ago. Unfortunately, the wait commands in your script render my example useless.

The way you call the presentation handler in the arrowkey handler only adds to the irresponsiveness of your programme. If the user presses the arrowkey several times, s/he'll get the feeing that the programme is out of control and will probably press the arrowKey a few more times and eventually give up.

Try "something" like this:

Code: Select all

on presentation
  put false into lAllowArrowKeys
  show grc 1 -- cross, square or so
  send presentation 2 to me in 150 millisecs
end presentation

on presentation2
  show grc 2 -- arrow?
  put true into lAllowArrowKeys
end presentation2

on arrowKey theKey
  if lArrowKeys is true then
    -- store the millisecs etc
    send "presentation" to me in 0 millisecs
  else
    beep
  end if
end arrowKey
The above is only a prototype of what you are trying to do. What I want to show is how you can do this without using the wait command. Also, the additional beep gives the user a feeling of responsiveness.

I hope this helps.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

ThierryO
Posts: 7
Joined: Thu Mar 13, 2008 11:35 am

Post by ThierryO » Wed Mar 19, 2008 6:31 pm

Hi Mark,

All problems are now fixed! I replaced all "wait" and added handlers as you suggested. The stack runs greatly. Thank you very much!

Best,
Thierry

Post Reply

Return to “Mac OS”