Java Keybinding Plus Key [英] Java Keybinding Plus Key

查看:87
本文介绍了Java Keybinding Plus Key的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建用于放大和缩小我正在创建的图像编辑应用程序的快捷方式,我发现了一些奇怪的东西。要绑定 ctrl + + 的组合,我必须使用 = 键和一个控制和移位掩码:

I was trying to create shortcuts for zooming in and out in an image editing application I'm creating and I noticed something strange. To bind the combination of ctrl + +, I had to use the = key and a control and shift mask:

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK),"ZoomIn");

我试图直接绑定到 VK_PLUS 工作:

Neither of the combinations where I tried to directly bind to VK_PLUS worked:

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK),"ZoomIn");

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, KeyEvent.CTRL_DOWN_MASK),"ZoomIn");

它现在可以使用第一行代码,但我想知道为什么底部都没有两个工作,如果键盘没有 + 键作为移位的 = 键,理论上可能会出现问题。

It works right now with the very first line of code, but I was wondering why neither of the bottom two work and if this could (theoretically) be a problem if a keyboard did not have the + key as the shifted = key.

推荐答案

对于数字键盘加试试 KeyEvent.VK_ADD

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD,
                KeyEvent.CTRL_DOWN_MASK), "plus");

对于主键盘上的加号(美国键盘布局),请使用:

For plus on main keyboard (US keyboard layout) use:

getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK),"plus"); 

对于非美国键盘使用 VK_PLUS 。请参阅 4262044 6942481 进行一些澄清。

For non US keyboard use VK_PLUS. See bugs 4262044 and 6942481 for some clarifications.

这篇关于Java Keybinding Plus Key的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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