简体   繁体   English

Ctrl+B 键盘绑定如何工作?

[英]How does Ctrl+B keyboard binding works?

The Ctrl + B in Word and other shortcuts work the same no matter what language I'm using - how is this binding done?无论我使用什么语言, Word中的Ctrl + B和其他快捷方式的工作方式都是一样的 - 这种绑定是如何完成的? Can it be done in Java?可以在Java中完成吗?

If I understand you correctly I wonder that typing Ctrl + B creates different key code when you are using different languages?如果我理解正确,我想知道当您使用不同的语言时键入Ctrl + B会创建不同的键码? In this case look into KeyEvent API.在这种情况下,请查看 KeyEvent API。 It has 2 relevant methods: getKeyCode() and getKeyChar().它有 2 个相关方法:getKeyCode() 和 getKeyChar()。

getKeyChar() invoked when key is down depends on current language.按键关闭时调用的 getKeyChar() 取决于当前语言。 getKeyCode() does not depend. getKeyCode() 不依赖。 It always return the code of the key, not the letter associated with it.它总是返回密钥的代码,而不是与其关联的字母。 Moreover I found that (at least on my system - Linux Fedora) getkeyChar() invoked on key released returns the English character even when current language is different.此外,我发现(至少在我的系统上 - Linux Fedora)即使当前语言不同,在键释放时调用的 getkeyChar() 也会返回英文字符。

Here are the results of pressing and releasing of the same key with 3 different input languages installed on my system: English, Russian and Hebrew.以下是在我的系统上安装了 3 种不同输入语言的情况下按下和释放同一键的结果:英语、俄语和希伯来语。

pressed: ф 65 released: a 65 pressed: a 65 released: a 65 pressed: ש 65 released: a 65按下:ф65 释放:a 65 按下:a 65 释放:a 65 按下:ש 65 释放:a 65

As you can see the key code is always the same although the char is different.如您所见,尽管字符不同,但关键代码始终相同。

See How to Use Key Bindings for an explanation of how this works in Swing.有关如何在 Swing 中工作的说明,请参阅如何使用键绑定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java中嵌入的Javascript-如何进行声明? (Ctrl + B)(Nashorn)(IntelliJ) - Javascript embedded in Java - How can I go-to-declaration? (Ctrl+B) (Nashorn) (IntelliJ) 为什么\\ B有效但\\ b不起作用 - why does \B works but not \b 您如何在Jython中拦截键盘中断(CTRL-C)? - How do you intercept a keyboard interrupt (CTRL-C) in Jython? 如何为 JMenuItem 设置键盘快捷键为 CTRL + S + A? - How can i set a keyboard shortcut to CTRL + S + A for a JMenuItem? 如何使用 Javafx KeyCombination 覆盖系统默认键盘快捷键,如 Ctrl+C、Ctrl+V? - how to overwrite system default keyboard shortcuts like Ctrl+C, Ctrl+V by using Javafx KeyCombination? 如何以编程方式确定不同键盘布局上“Ctrl + Plus”和“Ctrl + Minus”的正确击键? - How to programmatically determine the correct keystroke for "Ctrl + Plus" and "Ctrl + Minus" on different keyboard layouts? 如何使JTabbedPane不捕获Ctrl + Tab键绑定? - How to make JTabbedPane not to catch Ctrl+Tab key binding? Java代码无法识别ctrl-m(^ M),但适用于其他ctrl-characters(^ Q,^ A,^ T等)Linux - Java code does not recognize ctrl-m(^M) but works fine for other ctrl-characters(^Q,^A,^T etc) Linux Double.compare(a[0],b[0])) 如何工作? - How Double.compare(a[0],b[0])) works? B-Tree如何在序列化方面起作用? - How B-Tree works in term of serialisation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM