- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我不明白为什么这会给出错误并且不被视为平等。
KeyStroke test1 = KeyStroke.getKeyStroke('1');
KeyStroke test2 = KeyStroke.getKeyStroke(KeyEvent.VK_1, 0);
System.out.println(test1.equals(test2));
在什么情况下这不相等,即这是一个功能还是一个错误?
最佳答案
您在第一行中传递的是一个字符
,KeyEvent.VK_1
是一个以十六进制 (0x30) 表示的整数
。数字和键由具有十六进制值的基本类型 int
表示。
例如:从 0 到 9 的数字用十六进制表示如下:
public static final int VK_0 = 0x30;
...
public static final int VK_9 = 0x39;
它们是不同的,因为第一个 KeyStroke 认为输入了数字 1
第二个 KeyStroke 正在考虑按下 1。
它们不是不同的键,而是不同的操作
KeyStroke test1 = KeyStroke.getKeyStroke('1', KeyEvent.KEY_LOCATION_UNKNOWN);
KeyStroke test2 = KeyStroke.getKeyStroke(KeyEvent.VK_1, KeyEvent.KEY_LOCATION_UNKNOWN);
System.out.println(test1.equals(test2));
这将是true
那个0参数KeyStroke.getKeyStroke(KeyEvent.VK_1, 0);
表示常量KeyEvent.KEY_LOCATION_UNKNOWN
文档说:
A constant indicating that the keyLocation is indeterminate
or not relevant.
KEY_TYPED events do not have a keyLocation; this value
is used instead.
关于java - 为什么类似的 keyChar 和 keyCode 在 KeyStroke 中不相等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22225508/
我正在尝试进行按键绑定(bind)。我想生成一个 KeyStroke,仅当按住控制键时才会执行操作。我不明白我做错了什么,我对其他键绑定(bind)使用相同的技术(Control+up、Control
我正在使用以下标准 GenerateKey 代码: void GenerateKey ( int vk , BOOL bExtended) { KEYBDINPUT kb={0}; INPU
好的,所以我有一个带有 Hammerspoon 的脚本,可以为我执行按键操作。简单的例子: hs.hotkey.bind({'cmd','alt','ctrl'}, "b", function()
我该如何制作具有多个修饰符蒙版的梯形失真校正?由于缺乏明确指定命令掩码,Apple 建议使用以下方法来获取掩码: Toolkit.getDefaultToolkit().getMenuShortcut
我想知道如何声明新的 KeyStroke - 按下和释放?例如我可以这样做: KeyStroke.getKeyStroke("pressed F10"); KeyStroke.getKeyStroke
我有一个问题,为什么这个 KeyStroke 的修饰符从 128 变成了 130? package de.roth.jsona.keyevent; import java.awt.event.Inpu
如何在 Delphi 中使用 TTouchKeyboard,以便它可以将击键发送到其他程序。例如,我想使用 TTouchKeyboard 组件在浏览器中输入密码。我不知道如何让浏览器在我点击键盘时保持
我想将 KeyStrokes 添加到 CheckBox 组中,因此当用户点击 1 时,击键将选择/取消选择第一个 JCheckBox。 我已经编写了这部分代码,但它不起作用,有人可以指出我正确的方向吗
我即将在 swing 应用程序中使用键盘绑定(bind)作为数字键盘输入键,但该键很难捕捉。我见过的所有例子都依赖于类似 key == KeyEvent.VK_KP_LEFT 其中 VK_KP_LEF
阅读了一些教程后,我决定从 KeyListeners 切换到 KeyBindings。我想我已经理解它们是如何工作的,但我不明白为什么这个小程序即使我不释放 key 也会检测到 key 释放。编辑:我
我的 UI 中的用例是根据双击 JList 中的项目来填充两个 JTextField 组件。简单的方法是使用 JCheckBox 填充 jTextField1 如果复选框被选中,则填充另一个(如果未选
关于覆盖 equals() 和 hashCode() 的几个答案描述了对两者的需求以及在 Java 中将它们用作 HashMap 中的键的应用。我的问题是,将 Java KeyStroke 类作为键放
我想控制哪个击键属于哪个Jcomponent。我什至想了解如何删除与 Jcomponent 关联的默认击键并将它们替换为其他喜欢的击键。 我关注了这个神谕tutorial ,它给出了一个 JButto
当用户按下 Enter 键时,我需要将焦点转移到另一个元素上,所以我成功地通过这种方式在大多数元素上注册了 KeyStroke: this.getInputMap( ).put( KeyStroke
我想为 键,然后在我的 JFrame 上使用它。 我正在使用以下代码尝试为 的击键? 最佳答案 根据 the documentation对于 getKeyStroke(char): Returns
在带有 Swing GUI 的小型 Java 独立程序中,我将 JMenuItem 与 Accelerator 一起使用 - 基本上没有任何问题: JMenuItem item = new JMe
我真正想做的是为 Google Chrome 浏览器添加更多快捷方式。截至目前,我正在使用 window.addEventListener('keyup', keyCheck, false); . 然
是否有 KeyStroke 的鼠标等效类?我正在寻找某种围绕 MouseEvent 的包装器来描述按下了哪个按钮(我可以通过 SwingUtilities 获得它),以及使用的任何修饰符。这个想法是我
我怎样才能最好地实现一个系统,通过 iPhone 和/或 Droid 将击键/命令通过 WiFi 或蓝牙发送到台式机或笔记本电脑?有 VLC、Keynote 和其他应用程序的应用程序可以执行此操作,所
我无法将 Control-Backspace 键映射到 KeyStroke。以下内容对我来说毫无意义。 import java.awt.event.KeyEvent; import javax.swi
我是一名优秀的程序员,十分优秀!