robot.keyPress(KeyEvent.k);
This won't work, because this will attempt to find a static
member
of the class KeyEvent
called k
. You've named your incremental object k
, so use k
.
robot.keyPress(k.getKeyCode());
More thorough Explanation
When you say the following:
String[] strs = {"hello", "there", "my", "friend"};
for(String str : strs)
{
// Do something.
}
What you're making the computer do has the same effect as:
for(int x = 0; x < strs.length; x++)
{
String str = strs[x];
}
So you're defining a String
object named str
that will contain the current String
object that is contained within the strs
array.