Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9036453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:00:03+00:00 2026-06-16T09:00:03+00:00

My current project involves automation using Java’s Robot class, to simulate key presses. My

  • 0

My current project involves automation using Java’s Robot class, to simulate key presses.
My problem is that certain keycodes are invalid to pass to the Robot’s keypress(int keycode) method.

What I already know:

After reading the solution to this question: Why are some KeyEvent keycodes throwing IllegalArgumentException: Invalid key ocode, I started modifying my code, changing certain symbols like £ (VK_DOLLAR) to VK_SHIFT + VK_3, & (VK_AMPERSAND) to VK_SHIT + VK_7, etc …

My question:

My question, however is how to determine what key gives what symbol when combined with shift, since different keyboards (and often times different keyboard configurations from the OS) change these.

A typical example is the @ (at symbol) and " (double quote). VK_SHIFT + VK_2 may be the at symbol on some systems while maybe a double quote on others.

Is there anyway in Java to check, prior to invoking the Robot keypress, on which key a symbol relies ?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:00:07+00:00Added an answer on June 16, 2026 at 9:00 am

    I already went through IllegalArgumentException when using robots. It’s because of your keyboard layout. My solution was to use Alt codes:

    public static void alt(int event1, int event2, int event3, int event4) throws Exception {
    
    Robot bot = new Robot();
    bot.delay(50); //Optional
        bot.keyPress(KeyEvent.VK_ALT);
    
            bot.keyPress(event1);
            bot.keyRelease(event1);
    
            bot.keyPress(event2);
            bot.keyRelease(event2);
    
            bot.keyPress(event3);
            bot.keyRelease(event3);
    
            bot.keyPress(event4);
            bot.keyRelease(event4);
    
        bot.keyRelease(KeyEvent.VK_ALT);
    
    }
    

    It makes easy to send Alt codes.

    For example, if you want an ampersand just use alt(KeyEvent.VK_NUMPAD0, KeyEvent.VK_NUMPAD0, KeyEvent.VK_NUMPAD3, KeyEvent.VK_NUMPAD8);

    You just got to make sure Num Lock is on.

    A useful site to get the alt codes you’ll need is http://www.alt-codes.net/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My current project involves using LDAP (Active Directory) and I'm using issue tracking for
My current project involves setting up a bunch of sidebar links, such that the
My current project involves deploying an upgraded .exe file that runs as a Windows
I am working on a project that involves animating an image using a sequence
My team's current project involves re-writing retrieval libraries in JavaScript. We are basically looking
For my current project I have to send a signature from PHP to Java
My current project for work involves developing a SharePoint 2007 WebPart which will be
I am working on a large project that involves taking thousands (30,000+) static web
Background: Our current system involves two services (one written in Java, the other in
My current task is taking a Java project written and developed in Ubuntu NetBeans

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.