开发者

How does Ctrl+B keyboard binding works?

开发者 https://www.devze.com 2023-03-18 23:29 出处:网络
The Ctrl+B in Word and othe开发者_运维问答r shortcuts work the same no matter what language I\'m using - how is this binding done? Can it be done in Java?If I understand you correctly I wonder that ty

The Ctrl+B in Word and othe开发者_运维问答r shortcuts work the same no matter what language I'm using - how is this binding done? Can it be done in Java?


If I understand you correctly I wonder that typing Ctrl+B creates different key code when you are using different languages? In this case look into KeyEvent API. It has 2 relevant methods: getKeyCode() and getKeyChar().

getKeyChar() invoked when key is down depends on current language. getKeyCode() does not depend. 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.

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.

pressed: ф 65 released: a 65 pressed: a 65 released: a 65 pressed: ש 65 released: 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消