should KbName('Return') return two keycodes?

Typing this returns two key codes:
>> KbName('return')

ans =

40 158

Is that right? I expected just one. The example code provided in the help for KbName seems to assume that only one value will be returned.

yesKey = KbName('return');
[a,b,keyCode] = KbCheck;
if keyCode(yesKey)
flushevents('keyDown');
...
end;
Since yesKey=[40 158], the "if" argument is keyCode([40 158]), which yields two values, e.g. 0 1. Providing two values to "if" does not trigger an error, but "if" uses only the first and ignores the second value. Is that right?

Best
Denis
p.s.
Calling KbName('UnifyKeyNames') or not makes not difference.


photo
Denis Pelli
Professor of Psychology & Neural Science, New York University

Denis,

 

I think that something is wrong in your copy of PsychToolbox. KbName('return') has always returned 13 and still does for me.

 

Ted

 

From: PSYCHTOOLBOX@yahoogroups.com [mailto:PSYCHTOOLBOX@yahoogroups.com]
Sent: Wednesday, June 28, 2017 1:49 PM
To: Mario Kleiner <mario.kleiner.de@...>; Psychtoolbox psychtoolbox <psychtoolbox@yahoogroups.com>
Subject: [PSYCHTOOLBOX] should KbName('Return') return two keycodes?

 

 

Typing this returns two key codes:

>> KbName('return')

 

ans =

 

    40   158

 

Is that right? I expected just one. The example code provided in the help for KbName seems to assume that only one value will be returned.

 

yesKey = KbName('return');           

   [a,b,keyCode] = KbCheck;

   if keyCode(yesKey)

     flushevents('keyDown');

     ...

   end;

 

Since yesKey=[40 158], the "if" argument is keyCode([40 158]), which yields two values, e.g. 0 1. Providing two values to "if" does not trigger an error, but "if" uses only the first and ignores the second value. Is that right?

 

Best

Denis

p.s.

Calling KbName('UnifyKeyNames') or not makes not difference.

 

 

photo

Denis Pelli
Professor of Psychology & Neural Science, New York University

thanks. that's puzzling. I quit and restarted MATLAB. I downloaded a fresh copy of psychtoolbox, deleting my old one, and i still get the dual answer:
>> KbName('Return')

ans =

40 158

MacBook Air, macOS 10.12.5, MATLAB 2015b.

I can't imagine what significant difference there might be between my setup and yours.
thanks.
denis


Denis Pelli
Professor of Psychology & Neural Science, New York University

On Wed, Jun 28, 2017 at 5:13 PM, 'Ted Wright' cewright@... [PSYCHTOOLBOX] <PSYCHTOOLBOX@yahoogroups.com> wrote:

Denis,

I think that something is wrong in your copy of PsychToolbox. KbName('return') has always returned 13 and still does for me.

Ted

From: PSYCHTOOLBOX@yahoogroups.com [mailto:PSYCHTOOLBOX@ yahoogroups.com]
Sent: Wednesday, June 28, 2017 1:49 PM
To: Mario Kleiner <mario.kleiner.de@...>; Psychtoolbox psychtoolbox <psychtoolbox@yahoogroups.com>
Subject: [PSYCHTOOLBOX] should KbName('Return') return two keycodes?

Typing this returns two key codes:

>> KbName('return')

ans =

40 158

Is that right? I expected just one. The example code provided in the help for KbName seems to assume that only one value will be returned.

yesKey = KbName('return');

[a,b,keyCode] = KbCheck;

if keyCode(yesKey)

flushevents('keyDown');

...

end;

Since yesKey=[40 158], the "if" argument is keyCode([40 158]), which yields two values, e.g. 0 1. Providing two values to "if" does not trigger an error! , but "if" uses only the first and ignores the second value. ! Is that right?

Best

Denis

p.s.

Calling KbName('UnifyKeyNames') or not makes not difference.

Denis Pelli
Professor of Psychology & Neural Science, New York University


same here.

on OS X 10.12.5, Mid-2014 MacBook Pro Retina. MATLAB 2014b, latest PsychToolbox.

btw, if you pass 'if' a vector, it will only return true if all the elements of the vector meet the logical test.
Yes, that's correct behavior if your OS maps multiple keys called "Return", ergo multiple key codes. Some keyboards under OSX have two different keycodes for Return. On Windows the system only defines one keycode for Return.

You'd need to test if any(keycode(...)) to handle that.
-mario

First, thank you for this amazing toolbox. I have been a new user for only 3 days and I love it. While searching the forum, I came across this post.

Just for the record, KbName(‘return’) returns 40 158 on my macbook pro as well.
So, the best way to deal with this is to use indeed, ĂŹf any(keycode)`.

Another related question:

On my macbook keyboard the key with number 5 has on it also the % symbol (functional key). KbName(‘5%’) returns 34 and KbName(‘5’) 93.

Running a simple exmaple, using as trigger triggerCode = KbName('5%');, when 5 is pressed it works.
If I use triggerCode = KbName('5'); and press the 5, nothing happens.

Why is that ? The only way to find the correct names is to use:

>> KbQueueRelease
>> KbQueueCreate;
>> KbQueueStart; WaitSecs(5);
>> [pressed, firstPress, firstRelease, lastPress, lastRelease] = KbQueueCheck();
>> KbName(find(firstPress))

{'2@'}    {'3#'}    {'4$'}    {'5%'}    {'6^'}   

The ‘5’ is for the number 5 on a numeric keypad. If your keyboard doesn’t have such a separate numeric input block, you can’t input that ‘5’.

If you just type KbName + ENTER in the Octave or Matlab command window, and then type a key, KbName will print the proper string to use, e.g., ‘5%’.

-mario

Thanks.

One last thing. I have got a script from a colleague that used PTB on windows. He has hard-coded some keypresses like KbName(find(keycode)) == 42 for example.

I have a macbook. How can I figure out to which key does 42 corresponds on a window machine so that I change this in the code and run it on my laptop ??

http://psychtoolbox.org/docs/KbName tells you all there is to know. Btw. we would appreciate your lab buying a community membership with priority support to support future upkeep and support for this toolbox. This is also what is needed for me to keep answering any further questions:

http://psychtoolbox.org/contribute

-mario

1 Like

Thank you so much. Of course I would more than happy to discuss with my lab about contributing.

With the priority membership, the “up to 3 questions” limit is monthly/daily or yearly?

I need to know that before I discuss with my PI

You can ask questions for up to 1 year after purchase date. The limit is a total of 3 questions, but in total all questions combined must not take more than 1 hour of my time. So you buy in total one hour of my time, which can be split up into up to three chunks. The fine-print also states that it can take up to 2 weeks after purchase before you can use your license, because this is supposed to act as an insurance in case of need and contribute to the substantial costs of keeping PTB in good shape, not as a way to buy help for cheap if “the house is already burning”. Also there are rare times where the priority support can be delayed, e.g., if i’m on vacation or if i would be sick, although for most of the year support will be within 1-2 business days.

E.g., myself and the parts of the company responsible for sales and license management will be on vacation for large parts of August and also myself early September, so nobody will get any support between 21. August and 6. September, and if one hasn’t bought a license before start of next week, one won’t get any support until 6. September.

The basic rule is though that without such a license, you won’t get any expert advice at all anymore.

The emphasis here is that we want contributions without labs using the full time, as the “leftover” time is used to fund development of new PTB features, general improvements, bug fixes, user support etc. So far this is not working well, and if labs continue to be too stingy, we will have to think about something way more expensive, ie. a radical change in business model, or simply terminate all future work and support on Psychtoolbox and other related neuroscience software.

Thanks for your potential support,
-mario