在Java中使用组合键 [英] Using key combination in Java

查看:98
本文介绍了在Java中使用组合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个Java应用程序,需要使用死键"或键修饰符输入特殊符号.例如,用户应该可以通过按`+ n"来输入ñ".

我考虑过使用键侦听器,但是在更改文档之前,将处理由键触发的任何事件,并且我无法更改该更改.我也不能更改密钥本身以允许直接输入所需的符号.

请告知.

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.

推荐答案

我发现从键侦听器调用的KeyEvent.setKeyChar()方法可以替换输入的char.这使我可以使用ESC键作为前缀进行字符翻译.

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.

这篇关于在Java中使用组合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆