2

I created Robot class in JAVA but there is a issue robot.keyPress(KeyEvent.VK_AT) have to press -> '@' -> at

But it presses 'q' <-> 'Q'

What should i do to robot press '@' symbol ?

Vinay Veluri
  • 6,671
  • 5
  • 32
  • 56
Ertuğrul Çetin
  • 5,131
  • 5
  • 37
  • 76

2 Answers2

3

On my keyboard, the @ key requires combining the Shift and 2 keys; others may vary. The test image below was produced by adding the following to this example.

Addendum: As noted in comments by @neat159, the host OS keyboard control panel setting must match the intended keyboard layout being tested.

r.keyPress(KeyEvent.VK_SHIFT);
r.keyPress(KeyEvent.VK_2);
r.keyRelease(KeyEvent.VK_2);
r.keyRelease(KeyEvent.VK_SHIFT);

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • i'm using ubuntu 13v how can i do with ubuntu ? – Ertuğrul Çetin Feb 21 '14 at 18:00
  • my combination is [Alt Gr] + [Q] = '@' but i get errorException in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid key code at sun.awt.windows.WRobotPeer.keyPress(Native Method) at java.awt.Robot.keyPress(Unknown Source) at RobotTest$1.mouseReleased(RobotTest.java:37) at java.awt.Component.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) – Ertuğrul Çetin Feb 21 '14 at 18:05
  • Works for me on Ubuntu 12, IcedTea6. – trashgod Feb 21 '14 at 18:15
  • It's really interesting it drives me crazy i'm working on it almoust 5 hours. Now I Tried on WINDOWS 7 Getting Same Issue also combination is [Alt Gr] + [Q] = '@' What is the problem i dont get it? My Code is: robot.keyPress(KeyEvent.VK_ALT_GRAPH); robot.keyPress(KeyEvent.VK_Q); robot.keyRelease(KeyEvent.VK_Q); robot.keyRelease(KeyEvent.VK_ALT_GRAPH); I'm getting Error: Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid key code at sun.awt.windows.WRobotPeer.keyPress(Native Method) at java.awt.Robot.keyPress(Unknown Source) – Ertuğrul Çetin Feb 21 '14 at 18:18
  • 1
    You may have to change something in the host OS's keyboard control panel; mine's set to U.S. for both Mac OS X and Ubuntu. Interestingly, mine accepts a `VK_ALT` modifier, but silently ignores `VK_ALT_GRAPH`. – trashgod Feb 21 '14 at 18:23
  • 2
    yes you were right my keybouard language was turkish so the problem is language i changed it to english problem solved thanks. – Ertuğrul Çetin Feb 21 '14 at 18:37
0

Have you tried using the constant KeyEvent.VK_AMPERSAND ?

Slimu
  • 2,301
  • 1
  • 22
  • 28