简体   繁体   English

MATLAB中的Java Robot和KeyEvent

[英]Java Robot and KeyEvent in MATLAB

I have a question regarding using robot and keyevent in MATLAB 我有一个关于在MATLAB中使用机器人和键盘事件的问题

import java.awt.Robot;
import java.awt.event.KeyEvent;
robot = Robot;
if isequal(eventdata.Key,'return')  % capture enter 
  robot.keyPress(KeyEvent.VK_ENTER);
  robot.delay(0.1);
  robot.keyRelease(KeyEvent.VK_ENTER);
end

This block of code performs its function correctly. 此代码块正确执行其功能。 However, it create an enter event outside from the form itself. 但是,它在表单本身之外创建了一个enter事件。 How do I contain it in the active form or gui only not in other documentation ? 如何仅以活动形式或gui包含它,而不包含在其他文档中?

I had a similar problem and was able to solve it by setting focus to the desired figure in addition with some "waiting": 我有一个类似的问题,并且能够通过将焦点设置为所需的数字以及一些“等待”来解决它:

figure(myfigureHandle) %set focus to myFigure
pause(1) %wait for a short amount of time
import java.awt.Robot; import java.awt.event.*; SimKey=Robot;... %doing the robot stuff

In your case, the pause-command should only be used, when you are within the if-condition. 在您的情况下,仅当您处于if条件内时,才应使用pause-command。

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM