问题
I develop a Java application and need to enable entering special symbols by using a 'dead' key or key modifiers. For example, the user should be able to enter 'ñ' by pressing '`+n'.
I considered using key listeners but any event fired by a key is processed before the document is changed and I cannot alter that change. I also cannot change the key itself to allow direct entering the required symbol.
Please advise.
回答1:
I have found that KeyEvent.setKeyChar() method called from a key listener can replace the entered char. This allowed me to make char translation using ESC key as the prefix.
来源:https://stackoverflow.com/questions/32246698/using-key-combination-in-java