How Can I Write A Program Pressing a Key?

Hi i'm going to to use matlab for pressing keys when something changed in the screen (left arrow and right arrow keys specially), so what can i do for this? thanks

답변 (1개)

Geoff Hayes
Geoff Hayes 2017년 6월 24일

0 개 추천

Mahan - if you are using a MATLAB figure (which is the screen with something changing on it), you can assign a function callback to the WindowKeyPressFcn property of the figure. This callback would be called so long as the figure has focus. Try using the following code in a file saved as KeyPressFcnTest.m
function KeyPressFcnTest
close all;
h = figure;
set(h,'WindowKeyPressFcn',@KeyPressFcn);
function KeyPressFcn(~,event)
fprintf('key event is: %s\n', event.Key);
end
end
The event.Key will give you the name of the keyboard button pressed (rightarrow, leftarrow, etc.).

댓글 수: 3

Mahan Vaezzadeh
Mahan Vaezzadeh 2017년 6월 24일
assume that i have a page opened on google chrome and i want a left arrow be pressed every 5 sec,how can i do that?!
Geoff Hayes
Geoff Hayes 2017년 6월 24일
Does the left arrow interact with the open page on the Google Chrome browser? Please clarify what you are attempting to do.
Mahan Vaezzadeh
Mahan Vaezzadeh 2017년 6월 24일
yes,the left arrow inteact with the open page on the google chrome, sorry,my english is not very good

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

질문:

2017년 6월 24일

댓글:

2017년 6월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by