while trying to automate keyPress event in a loop, I get the error: "Unrecognized function or variable 'VK_i'

조회 수: 9(최근 30일)
I am trying to automate/simualte the keyboard to automatically generate/type numbers using the java robot class and I running into the following error: Unrecognized function or variable 'VK_i'. Could someone help. Here is my code snippet:
clc; clear; close all;
import java.awt.Robot;
import java.awt.event.*;
import java.awt.event.KeyEvent;
keybrd = java.awt.Robot; %Create a keyboard object
for i = 1:3
%num = num2str(i);
key = java.awt.event.KeyEvent.VK_i;
keybrd.keyPress(key);
keybrd.keyRelease(key);
end

채택된 답변

Voss
Voss 2022년 8월 8일
key = java.awt.event.KeyEvent.(sprintf('VK_%d',i));
  댓글 수: 2

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

추가 답변(0개)

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by