用于“控制"按钮的机器人按键. Mac上的键 [英] Robot Keypress for the "control" key on mac

查看:90
本文介绍了用于“控制"按钮的机器人按键. Mac上的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我Robot Keypress在Mac上的控制"键是什么? 我已经尝试了VK_Control,VK_META,CTRL_MASK和CTRL_DOWN_MASK仍然没有.

Can anyone tell me what the Robot Keypress is for the "control" key on mac? I've tried VK_Control, VK_META, CTRL_MASK and CTRL_DOWN_MASK still nothing.

请注意:它是Mac上唯一的控制键,位于左侧"fn"键旁边.不是选项或命令.谢谢

Please note: Its the only control key on mac next to the "fn" key lefthand side. Not option or command. Thanks

推荐答案

使用数字常量很不好.我可以在Groovy中提供运行示例,这将证明Robot.keyPress(KeyEvent.VK_CONTROL)正常运行.可能是您忘记了拨打releaseKey吗?

It's bad to work with numeric constants. I can provide running example in Groovy, that will proof that Robot.keyPress(KeyEvent.VK_CONTROL) is working perfectly. May it be, that you forgot call releaseKey?

P.S.带有此类代码段的Java 1.6在Macos Maveric上进行了测试.(Groovy)

P.S. Tested on Macos Maveric with Java 1.6 with such snippet.(Groovy)

已编辑(我想可能是您需要更改 Ctrl F12 的发布顺序. F12 应该是释放,同时仍然按下 Ctrl ,则修改器将被正确设置,并且 F12 将被视为 Ctrl + F12 )

EDITED (I may suppose, you need to change Ctrl and F12 release order. F12 should be released, while Ctrl is still pressed, then modifiers will be setted correctly, and F12 will be treated as Ctrl+F12)

new SwingBuilder().frame(pack: true, show: true, defaultCloseOperation: JFrame.EXIT_ON_CLOSE) {
    textField(keyPressed: { KeyEvent e ->
        println("$e.keyCode, $e.modifiers") // prints 123 2 in response to Robot event.
        if (e.keyCode == KeyEvent.VK_SPACE)
        {
            new Robot().with {
                robot.keyPress(KeyEvent.VK_CONTROL);
                robot.keyPress(KeyEvent.VK_F12);
                robot.keyRelease(KeyEvent.VK_F12); // Release it first.
                robot.keyRelease(KeyEvent.VK_CONTROL);
}    }     }) }

这篇关于用于“控制"按钮的机器人按键. Mac上的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆