How to programmatically press a key?

조회 수: 27 (최근 30일)
D Kemper
D Kemper 2019년 9월 10일
댓글: D Kemper 2019년 9월 10일
How can I programmatically press a key in Matlab? I click outside of the Matlab environment by the java.awt.Robot command, but after that I would like to press some keys (e.g. type "Hello"). I tried the keyPress(KeyEvent.VK_H) command found online, but that does not seem to work. Any suggestions?
This is the code I tried:
import java.awt.Robot;
import java.awt.event.*;
robot = Robot();
robot.mouseMove(1100,54);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.keyPress(KeyEvent.VK_V);
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 9월 10일
You also need to send the key release event.
D Kemper
D Kemper 2019년 9월 10일
Thanks! That solves the problem.

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

답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by