0

I am having a hard time figuring out how the KbCheck function works and how I can use it to pause whatever my program is doing, wait for the spacebar to be pressed and then resume with the program.

KbCheck's documentations has this:

[keyIsDown, secs, keyCode, deltaSecs] = KbCheck([deviceNumber])

I know keyIsDown will constantly return 0 until the user presses any key, after which it will return 1. But, how do I use KbCheck with a while loop to do the above?

4

2 回答 2

2

KbCheck在您调用它时只进行一次检查。我认为你想要的是KbWait,它将停止程序的执行,直到它得到按键:

[secs, keyCode, deltaSecs] = KbWait([deviceNumber][, forWhat=0][, untilTime=inf])

PsychToolbox 中有许多键盘检查功能,因此可能值得检查它们是否更适合您的特定需求,例如:

  • KbPressWait
  • KbStrokeWait
  • KbReleaseWait
于 2014-07-02T02:23:43.383 回答
0

如果您打算使用KbWait(),您应该明确知道您会得到一个时间抖动的反应时间。文档说最多 5 毫秒,这可能会或可能不会在分析过程中给您带来一些问题。

这就是文档所说的:

CAUTION: KbWait periodically checks the keyboard. After each failed check
(ie. no change in keyboard state) it will wait for 5 msecs before the
next check. This is done to reduce the load on your system, and it is
important to do so. However if you want to measure reaction times this is
clearly not what you want, as it adds up to 5 msecs extra uncertainty to
all measurements!

看一下解释它的演示:

edit KbDemo.m
于 2017-05-22T21:58:01.937 回答