I am writing a basic program that asks the user to type in a String, and I am trying to use a Robot (from java.awt.Robot
)that will type this message back into another document after a delay. The Problem I have now is that I need to convert whatever I get from message.charAt(i)
to a KeyEvent.VK_[insert Char]
KeyCode. Is there a better way to do what I am trying to do? I suppose I could always just have a massive switch statement that gets the appropriate KeyCode but I was hoping there would be a more elegant way. My first thought, having done python for awhile, was to make a string "KeyEvent.VK_" + message.charAt(i)
and convert that to code somehow, but I think the only way to do that is using Reflection which is discouraged.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…