KbName key press and hold timing

Hi everyone,

I'm curious about the timing of KbName when pressing and holding a key. In Windows, for example, using notepad or any text box, if you press and hold a key, you will get the initial character, and then a slight pause before additional repeated characters appear. Does KbName work underneath this level to avoid any sort of timing issues like this? The following is an example of this sort of issue that people have had to program around when writing Javascript programs (nothing to do with PsychToolbox, of course): http://stackoverflow.com/questions/3691461/remove-key-press-delay-in-javascript

Best,
Matthew
these figures aren't directly applicable, but they do give some idea about input device latency variations (in E-Prime, shudder):

http://www.pstnet.com/eprimedevice.cfm



--- In psychtoolbox@yahoogroups.com, Matthew Edmundson <medmunds@...> wrote:
>
> Thanks for the info, Mario. As far as under 100 ms response timing, this is
> an important point. We happen to be using gamepads, not keyboards, as our
> main input device, with the keyboard option only being a backup for
> flexibility in a pinch. That being said, we will have to test the response
> times of our gamepads. I'll look through the archives for more info.
>
> Best,
> Matthew
>
>
> On Thu, Jun 6, 2013 at 7:32 PM, Mario <mario.kleiner@...>wrote:
>
> > **
> >
> >
> > KbCheck and also the KbQueue functions operate at a lower level. They
> > won't be affected by such things. GetChar() et al. would behave like your
> > text editor wrt. keyboard repeats or keyboard repeat delays. This is not
> > really debouncing though, which usually refers to debouncing the keyboard
> > hardware, not the human in front of the keyboard, as with keyboard repeat
> > delays.
> >
> > However, standard keyboards/mice are generally not really suitable for <<
> > 100 msecs accuracy response time measurements due to their hardware design
> > and builtin debouncing, nothing software could do against that. The forum
> > has multiple posts about this topic.
> >
> > -mario
> >
> >
> > --- In psychtoolbox@yahoogroups.com, "elladawu" <elladawu@> wrote:
> > >
> > > its not an issue. as far as i can tell from its behaviour (i haven't
> > looked at the source code), PsychHID communicates with devices at a lower
> > level.
> > >
> > > for example, when using KbCheck, it is necessary to do your own
> > debouncing because KbCheck will return true for as long as a key is held
> > down. essentially what you are getting back is not a key press but rather
> > the state of the keyboard matrix.
> > >
> > > i haven't needed to use any of the KbQueue functions but from a quick
> > squizz it looks like they do debouncing for you.
> > >
> > >
> > > --- In psychtoolbox@yahoogroups.com, Matthew Edmundson <medmunds@>
> > wrote:
> > > >
> > > > Hi everyone,
> > > >
> > > > I'm curious about the timing of KbName when pressing and holding a
> > key. In
> > > > Windows, for example, using notepad or any text box, if you press and
> > hold
> > > > a key, you will get the initial character, and then a slight pause
> > before
> > > > additional repeated characters appear. Does KbName work underneath this
> > > > level to avoid any sort of timing issues like this? The following is an
> > > > example of this sort of issue that people have had to program around
> > when
> > > > writing Javascript programs (nothing to do with PsychToolbox, of
> > course):
> > > >
> > http://stackoverflow.com/questions/3691461/remove-key-press-delay-in-javascript
> > > >
> > > > Best,
> > > > Matthew
> > > >
> > >
> >
> >
> >
>
Here is a simple script to run KbQueue, enlighted by ajb12490's previous post. It seems working. Please let me know if anyone thinks it is still buggy or wrong. Thanks!

%--------- the script ------------------
commandwindow
KbName('UnifyKeyNames');

try
w = Screen('OpenWindow', 0, 0, [0 0 640 480]);
Screen('FillRect',w,127);
Screen('Flip',w);
escapeKey = KbName('ESCAPE');
spaceKey = KbName('space');

startSecs = GetSecs;

KbQueueCreate;
KbQueueStart;

while 1
Screen('FillRect',w,127);
Screen('Flip',w);
[keyIsDown, firstKeyPressTimes, firstKeyReleaseTimes, lastKeyPressTimes, lastKeyReleaseTimes]=KbQueueCheck;
t1 = firstKeyPressTimes(find(firstKeyPressTimes));
t2 = lastKeyPressTimes(find(lastKeyPressTimes));
t3 = firstKeyReleaseTimes(find(firstKeyReleaseTimes));
t4 = lastKeyReleaseTimes(find(lastKeyReleaseTimes));
if keyIsDown
fprintf('"%s" typed at time %.3f seconds\n', KbName(firstKeyPressTimes), t1 - startSecs);
fprintf('"%s" typed at time %.3f seconds\n', KbName(lastKeyPressTimes), t2 - startSecs);
disp('');
if firstKeyPressTimes(escapeKey)
break;
end
end
if length(unique(firstKeyReleaseTimes)) > 1 || length(unique(firstKeyReleaseTimes)) > 1
fprintf('"%s" released at time %.3f seconds\n', KbName(firstKeyReleaseTimes), t3 - startSecs);
fprintf('"%s" released at time %.3f seconds\n', KbName(lastKeyReleaseTimes), t4 - startSecs);
disp('');
end
end
PsychHID('KbQueueRelease')
sca;
catch ME
sca;
psychlasterror.message = ME.message;
psychrethrow(psychlasterror);
end
%------------------------ the output here -----------------

"LeftArrow" typed at time 0.558 seconds
"LeftArrow" typed at time 0.558 seconds
"RightArrow" typed at time 1.677 seconds
"RightArrow" typed at time 1.677 seconds
"LeftArrow" released at time 1.712 seconds
"LeftArrow" released at time 1.712 seconds
"LeftArrow" typed at time 2.897 seconds
"LeftArrow" typed at time 2.897 seconds
"RightArrow" released at time 2.936 seconds
"RightArrow" released at time 2.936 seconds
"RightArrow" typed at time 4.086 seconds
"RightArrow" typed at time 4.086 seconds
"LeftArrow" released at time 4.123 seconds
"LeftArrow" released at time 4.123 seconds
"RightArrow" released at time 5.381 seconds
"RightArrow" released at time 5.381 seconds
"DownArrow" typed at time 5.391 seconds
"DownArrow" typed at time 5.391 seconds
"RightArrow" typed at time 6.565 seconds
"RightArrow" typed at time 6.565 seconds
"DownArrow" released at time 6.609 seconds
"DownArrow" released at time 6.609 seconds
"RightArrow" released at time 7.795 seconds
"RightArrow" released at time 7.795 seconds
"LeftArrow" typed at time 7.804 seconds
"LeftArrow" typed at time 7.804 seconds
"LeftArrow" released at time 8.800 seconds
"LeftArrow" released at time 8.800 seconds
"UpArrow" typed at time 8.811 seconds
"UpArrow" typed at time 8.811 seconds
"UpArrow" released at time 9.821 seconds
"UpArrow" released at time 9.821 seconds
"RightArrow" typed at time 9.956 seconds
"RightArrow" typed at time 9.956 seconds
"LeftArrow" typed at time 10.973 seconds
"LeftArrow" typed at time 10.973 seconds
"RightArrow" released at time 10.962 seconds
"RightArrow" released at time 10.962 seconds
"LeftArrow" released at time 11.726 seconds
"LeftArrow" released at time 11.726 seconds
"ESCAPE" typed at time 11.767 seconds
"ESCAPE" typed at time 11.767 seconds
There's KbQueueDemo which shows you how to use most aspects of keyboard queues?

You shouldn't use PsychHID('KbQueueRelease') but KbQueueRelease, as that M-Function does additional accounting and error checking. Other than that, your script is probably ok - didn't check it in detail.

-mario

--- In psychtoolbox@yahoogroups.com, "ptbmin" <ptbmin@...> wrote:
>
> Here is a simple script to run KbQueue, enlighted by ajb12490's previous post. It seems working. Please let me know if anyone thinks it is still buggy or wrong. Thanks!
>
> %--------- the script ------------------
> commandwindow
> KbName('UnifyKeyNames');
>
> try
> w = Screen('OpenWindow', 0, 0, [0 0 640 480]);
> Screen('FillRect',w,127);
> Screen('Flip',w);
> escapeKey = KbName('ESCAPE');
> spaceKey = KbName('space');
>
> startSecs = GetSecs;
>
> KbQueueCreate;
> KbQueueStart;
>
> while 1
> Screen('FillRect',w,127);
> Screen('Flip',w);
> [keyIsDown, firstKeyPressTimes, firstKeyReleaseTimes, lastKeyPressTimes, lastKeyReleaseTimes]=KbQueueCheck;
> t1 = firstKeyPressTimes(find(firstKeyPressTimes));
> t2 = lastKeyPressTimes(find(lastKeyPressTimes));
> t3 = firstKeyReleaseTimes(find(firstKeyReleaseTimes));
> t4 = lastKeyReleaseTimes(find(lastKeyReleaseTimes));
> if keyIsDown
> fprintf('"%s" typed at time %.3f seconds\n', KbName(firstKeyPressTimes), t1 - startSecs);
> fprintf('"%s" typed at time %.3f seconds\n', KbName(lastKeyPressTimes), t2 - startSecs);
> disp('');
> if firstKeyPressTimes(escapeKey)
> break;
> end
> end
> if length(unique(firstKeyReleaseTimes)) > 1 || length(unique(firstKeyReleaseTimes)) > 1
> fprintf('"%s" released at time %.3f seconds\n', KbName(firstKeyReleaseTimes), t3 - startSecs);
> fprintf('"%s" released at time %.3f seconds\n', KbName(lastKeyReleaseTimes), t4 - startSecs);
> disp('');
> end
> end
> PsychHID('KbQueueRelease')
> sca;
> catch ME
> sca;
> psychlasterror.message = ME.message;
> psychrethrow(psychlasterror);
> end
> %------------------------ the output here -----------------
>
> "LeftArrow" typed at time 0.558 seconds
> "LeftArrow" typed at time 0.558 seconds
> "RightArrow" typed at time 1.677 seconds
> "RightArrow" typed at time 1.677 seconds
> "LeftArrow" released at time 1.712 seconds
> "LeftArrow" released at time 1.712 seconds
> "LeftArrow" typed at time 2.897 seconds
> "LeftArrow" typed at time 2.897 seconds
> "RightArrow" released at time 2.936 seconds
> "RightArrow" released at time 2.936 seconds
> "RightArrow" typed at time 4.086 seconds
> "RightArrow" typed at time 4.086 seconds
> "LeftArrow" released at time 4.123 seconds
> "LeftArrow" released at time 4.123 seconds
> "RightArrow" released at time 5.381 seconds
> "RightArrow" released at time 5.381 seconds
> "DownArrow" typed at time 5.391 seconds
> "DownArrow" typed at time 5.391 seconds
> "RightArrow" typed at time 6.565 seconds
> "RightArrow" typed at time 6.565 seconds
> "DownArrow" released at time 6.609 seconds
> "DownArrow" released at time 6.609 seconds
> "RightArrow" released at time 7.795 seconds
> "RightArrow" released at time 7.795 seconds
> "LeftArrow" typed at time 7.804 seconds
> "LeftArrow" typed at time 7.804 seconds
> "LeftArrow" released at time 8.800 seconds
> "LeftArrow" released at time 8.800 seconds
> "UpArrow" typed at time 8.811 seconds
> "UpArrow" typed at time 8.811 seconds
> "UpArrow" released at time 9.821 seconds
> "UpArrow" released at time 9.821 seconds
> "RightArrow" typed at time 9.956 seconds
> "RightArrow" typed at time 9.956 seconds
> "LeftArrow" typed at time 10.973 seconds
> "LeftArrow" typed at time 10.973 seconds
> "RightArrow" released at time 10.962 seconds
> "RightArrow" released at time 10.962 seconds
> "LeftArrow" released at time 11.726 seconds
> "LeftArrow" released at time 11.726 seconds
> "ESCAPE" typed at time 11.767 seconds
> "ESCAPE" typed at time 11.767 seconds
>