Key presses not being logged with kbCheck
19 次查看(过去 30 天)
显示 更早的评论
I have been mostly programming this task on the computer in my lab but I was trying to finalize and do debugging. On the lab computer, my keypresses were being logged with mostly the same code (~95%, I've made some placement changes). Now, (on my macOS laptop) it is not working. The variable keyIsDown reports no key is pressed (0) but somehow it is advancing through my loop. I have spent a couple hours trying to look at the documentation and perusing the internet, but nothing provides me to a solution. I know psychtoolbox has a neverending list of issues with functionality using macOs but Im wondering if I am just overlooking something in the code.
while KbCheck;
[keyIsDown, secs, keyCode] = KbCheck(-1);
if keyIsDown
if keyCode(accept_key) == 1
pchoice = 1;
trialMatrix(t,1)= cellstr(pchoice_name{pchoice});
WaitSecs(2);
FlushEvents('keyDown');
%%% some conditional statements for other keypresses follow but are not relevant to my question, so they have been removed (it's alot) %%%
else keyCode(reject_key); % this is what I have been pressing
pchoice = 2;
Screen('TextSize',ptb.win, 50);
DrawFormattedText(ptb.win, balance_string ,'center', 'center', [0 0 0]);
Screen('Flip', ptb.win);
WaitSecs(2);
FlushEvents('keyDown');
cd('/Users/janedoe/Documents/Task Code'); % if choice is reject...
fix=imread('fixationcross.jpg');
fixc= Screen('MakeTexture', ptb.win, fix);
Screen('DrawTexture', ptb.win, fixc,[],[]);
Screen('Flip', ptb.win);
end
trialMatrix(t,1)= cellstr(pchoice_name{pchoice});
end
end
5 个评论
Walter Roberson
2023-3-19
If I understand what you are saying earlier, on the Mac each time you execute
[keyIsDown, secs, keyCode] = KbCheck(-1);
then you get back keyIsDown is 0? And if I understand correctly, you are saying that despite KeyIsDown being 0, that the code is "advancing through your loop" ?
Could you clarify what it means for your code to be "advancing through your loop" ? Is there a statement inside of the if keyIsDown section that is being executed even though your debugging appears to show that KeyIsDown is 0?
Or is the point that keyIsDown never seems to be non-zero even though you are pressing keys? Because that would be a quite different question than if keyIsDown is 0 but some statement inside the if KeyIsDown executing anyhow.
Or is the problem that keyIsDown is non-zero even though no keys have been pressed?
Some users of Laptops experienced the problem of “stuck keys”: Some keys
are always reported as “down”, so KbWait returns immediately and KbCheck
always reports keyIsDown == 1. This is often due to special function keys.
These keys or system functionality are assigned vendor specific
key codes, e.g., the status of the Laptop lid (opened/closed) could be
reported by some special keycode. Whenever the Laptop lid is open, this key
will be reported as pressed. You can work around this problem by passing
a list of keycodes to be ignored by KbCheck and KbWait. See
“help DisableKeysForKbCheck” on how to do this.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!