How can I use a keypressfct without a figure?

Hello, I just want to use a keypressfct sort of thing, except for there is no figure in my code. I am just taking data and it is continuously displaying on the screen and I want to be able to press spacebar and have the code stop. Any suggestions? Thanks.

回答 (1 件)

Jan
Jan 2013 年 7 月 3 日

0 投票

A Keypress-function, which is not bound to a specific figure, is called a keylogger. Such programs are used to steal passwords usually and therefore I will not implement or share the corresponding code.
Instead of catching a pressed space bar, using a tiny GUI with a "Stop"-Button would be much more user-friendly due to the intuitive interaction. Then let the button change a globally readable property, e.g.:
H = uicontrol('Sytle', 'PushButton', 'String', 'Stop', ...
'Callback', 'delete(gcbf)');
for k = 1:1e6
disp(k);
drawnow;
if ~ishandle(H)
disp('Stopped by user');
break;
end
end

1 件のコメント

JP
JP 2013 年 7 月 3 日
編集済み: JP 2013 年 7 月 3 日
Well that code sort of worked, but it keeps crashing my program for some reason, I cant figure it out. Im probably going to look up the how to make a keylogger though because it would be useful not to have to build a gui in the future

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

カテゴリ

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

質問済み:

JP
2013 年 7 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by