Keyboard Output in MATLAB

3 views (last 30 days)
Sasan Ardaneh
Sasan Ardaneh on 19 Nov 2011
hi
i want to know if i can write a program in MATLAB to tell my PC that a button of its keyboard is pressed.
for example when that program runs ,the button " a " is pressed 3 times each 2 seconds.

Accepted Answer

Walter Roberson
Walter Roberson on 19 Nov 2011
Java Robot Class
  1 Comment
Sasan Ardaneh
Sasan Ardaneh on 20 Nov 2011
thank you so much Walter ... that works ;)

Sign in to comment.

More Answers (2)

Jan
Jan on 19 Nov 2011
Under Windows, you can use FEX: textinject.
A platform independent method is FEX: inputEmu. This is based on Java and explained on undocumented: gui-automation and undocumented automation-robot
  2 Comments
Sasan Ardaneh
Sasan Ardaneh on 20 Nov 2011
thanks pal
well ,can you illustrate one easy program in MATLAB ...
my main program is in MATLAB and i want a way to make output as keyboard code of computer.
Jan
Jan on 20 Nov 2011
@Sasan: The shown links contain a full description of the usage of the Java Robot. The inputEmu is a Matlab wrapper for the Java Robot also and it contains enough help text. I'm surprised that Walter's short answer solves your problem already.

Sign in to comment.


Sasan Ardaneh
Sasan Ardaneh on 20 Nov 2011
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
robot=Robot;
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
  1 Comment
Walter Roberson
Walter Roberson on 20 Nov 2011
Yes, that looks appropriate. I am pleased to see that you put in the keyRelease event, as it is common for people to think that only the keyPress is needed.

Sign in to comment.

Categories

Find more on Desktop in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!