Hello, I am trying to use Java Robot Class inside a Matlab Function Block in Simulink to simulate key-press and key-release. But I keep getting an error while running the simulink model: "Import statements are currently unsupported." My code looks something like this:
function y = fcn(u)
import java.awt.*;
import java.awt.event.*;
rob=Robot;
rob.keyPress(KeyEvent.VK_A)
rob.keyRelease(KeyEvent.VK_A)
y = [0 0];
If I simply write the above as a function in matlab or as a script, it works fine. I get the error only when trying to do it with the simulink block. Is there any work-around to avoid this problem? Or any fixes? I am using Matlab version 2017a.
Thanks in advance! -SD

 채택된 답변

Brian Hannan
Brian Hannan 2017년 8월 8일

0 개 추천

If you're using this block for simulation only, you can use coder.extrinsic to get around this. There's a discussion on this here.

추가 답변 (1개)

Adam Bazyl
Adam Bazyl 2017년 9월 19일

0 개 추천

Hello, could you show the code of the running program? Because I have the same problem but still have an error. Is that correct?
coder.extrinsic('import');

댓글 수: 1

Mohammad Shushtari
Mohammad Shushtari 2020년 8월 18일
편집: Mohammad Shushtari 2020년 8월 18일
Hi, did you find the solution to this problem?

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

카테고리

도움말 센터File Exchange에서 Call Java from MATLAB에 대해 자세히 알아보기

제품

질문:

2017년 8월 7일

편집:

2020년 8월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by