简体   繁体   中英

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? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM