本文介绍了Robot.keyPress不适用于VK_ALT_GRAPH(无效的键码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个远程应用程序.(鼠标-键盘)我只是在快速显示我的问题...

I'm working on a remoting app.(mouse - keyboard) I just showing fastly my issue...

它适用于'A'或一些基本字符.

It's working for 'A' or some basic characters.

    case "a":
    robot.keyPress(KeyEvent.VK_A);

但是我没有输入'@'字符.我的样子是这样的.

But I did'nt make '@' character. My way is look like this.

 case "@":
 robot.keyPress(KeyEvent.VK_ALT_GRAPH);
 robot.keyPress(KeyEvent.VK_Q);
 robot.keyRelease(KeyEvent.VK_ALT_GRAPH);

使用VK_ALT_GRAPH时看到异常;

I see the exception when I use VK_ALT_GRAPH;

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)

那是个错误吗?如何按'@'字符?也像这样,我做不到;$,#,? ,[,],{,},',* ...

Is that a bug? How can I press '@' char? Also like this, I cant do these ;$ , # , ? , [ , ] , {, } , ' , * ...

推荐答案

我知道这已经很老了,但是没有人给出正确的答案,在练习之后,我选择了解决方案.

I know that this is very old, but nobody gave a correct answer and after practicing I went with the solution.

那是我的键盘:

,如果要按@或#,则必须这样做:

and for press @ or # you must to do it:

            bot.keyPress(VK_CONTROL);
            bot.keyPress(VK_ALT);
            bot.keyPress(VK_3);

            bot.keyRelease(VK_CONTROL);
            bot.keyRelease(VK_ALT);
            bot.keyRelease(VK_3);

这篇关于Robot.keyPress不适用于VK_ALT_GRAPH(无效的键码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 06:35