Java sends analog Keyboard Message shift combination key

Source: Internet
Author: User

In Java, you can use Java. AWT. Robot to simulate messages such as keyboard messages and mouse messages.

First try

Robot robot = new Robot();robot.keyPress(KeyEvent.VK_CONTROL);robot.keyPress(KeyEvent.VK_ALT);robot.keyPress(KeyEvent.VK_RIGHT);robot.keyRelease(KeyEvent.VK_RIGHT);robot.keyRelease(KeyEvent.VK_ALT);robot.keyRelease(KeyEvent.VK_CONTROL);

Successfully executed the next piece of qqmusic: CTRL + ALT + Right

Next to kuwo: Ctrl + Shift + Right

Robot robot = new Robot();robot.keyPress(KeyEvent.VK_CONTROL);robot.keyPress(KeyEvent.VK_SHIFT);robot.keyPress(KeyEvent.VK_RIGHT);robot.keyRelease(KeyEvent.VK_RIGHT);robot.keyRelease(KeyEvent.VK_SHIFT);robot.keyRelease(KeyEvent.VK_CONTROL);

Crazy... No response. Do you not support the shift key? Google

Http://www.webdeveloper.com/forum/showthread.php? T = 221722

This elder brother encountered the same problem, but before December 31, year 45, he did not provide a solution, but gave a code to record the Keyboard Message. Through this code, he found that after pressing shift, pressing right will trigger the release event of shift and press event of right. Is it a Java bug and Google?

Https://forums.oracle.com/forums/thread.jspa? Threadid = 2230592

Another man-in-Law also encountered this problem. It seems that I am not alone, but also what happened in the past few months. Someone pointed out the problem at him, which is really a Java bug.

Bug 4908075
Bug 6463168

It is puzzling that the bug has been submitted for N years and has not been fixed yet.

Fortunately, there is a way to bypass this bug: Turn off the numlock keys

Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_NUM_LOCK, false);

This solves the problem that shift cannot be pressed together with other keys when sending a key combination message.

Http://weblogs.java.net/blog/joshy/archive/2003/08/swinghack_keybo.html

Later, it was found that the method was originally provided by a renxiong and ignored, but the website was not posted.

The pen is stopped...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.