How to use "getkey" correct ?

I am currently using "getkey" but it appears to include some falts. The worst one is that it stops matlab and goes to the matlab main window, however the maylab script still runs, but it is hard to use without seeing the figure of my apllication.
What alternative functions can be used instead of "getkey" ?
best regards
Ole

 採用された回答

Star Strider
Star Strider 2025 年 12 月 12 日

0 投票

I am not certain what you are doing. Two options could be waitfor or waitforbuttonpress. There are additional possibilities in the See Also section of both pages.

9 件のコメント

Ole
Ole 2025 年 12 月 12 日
Thanks for your answer. The waitforbuttonpress does almost work correct, with the exception that i have to press the key two time in order to get the input (still using "getkey")
Star Strider
Star Strider 2025 年 12 月 12 日
My pleasure!
I am still not certain what you want to do.
In the MATLAB Functions documentation, the section
might have functions that can do what you want. (The 'Control Flow' section is near the end of that page.)
.
Ole
Ole 2025 年 12 月 12 日
I am using a long complex procedure which is polled starting by reading a character from the keyboard. the start of this procedure is:
w = 0;
while w == 0
w = waitforbuttonpress;
end
ch2 = getkey;
if ch2 == 27 % if key = "escape": Set exit
Exit = 1;
end
Walter Roberson
Walter Roberson 2025 年 12 月 12 日
getkey() is a File Exchange contribution. There is no certainty that it still works in your release.
Ole
Ole 2025 年 12 月 12 日
Yes, I know that getkey() is not centain to use. However I am not sure how else to read the keybard. Using the waitforbottonpressed did actually prevent the system from showing the matlab-window in front of my application-figure. Therefore, I need a way to read that key-code which is resulting in having waitforbottonpressed to return the value "1". (That I do not know).
So sorry for all my questions, I wrote my matlab code some 25 years ago as a 5 year of speartime-activity in trying to solve a mayor problem with arrays of microphones. The concept I developed did actually obtain a patent which has now expiered due to lifetime. I am now on pension and 83 years old, for what reason my brain is not what it used to be.
Best regards, and thaks a lot for your help
Ole.
Star Strider
Star Strider 2025 年 12 月 12 日
My pleasure!
No wories about all your questions. That is what MATLAB Answers is for.
I apologise for not being able to solve your problem, since I am still not certain what it actually is.
Ole
Ole 2025 年 12 月 12 日
My problem is that I am using "getkey", how else to read the code of the key pressed ?
Star Strider
Star Strider 2025 年 12 月 12 日
The only other option I can think of that could work is inputdlg or its friends.
Walter Roberson
Walter Roberson 2025 年 12 月 12 日
Perhaps use a figure() or uifigure() WindowKeyPressFcn callback. https://www.mathworks.com/help/matlab/ref/matlab.ui.figure.html#buiwuyk-1-KeyPressFcn

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

リリース

R2021a

質問済み:

Ole
2025 年 12 月 12 日

コメント済み:

2025 年 12 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by