英文:
Missing Character For KeyEvent
问题
使用KeyListener
的KeyTyped
方法时,有时候我会得到“丢失字符”的问题。我将展示我用来获取字符的代码,然后提出我的问题。
public class KeyInput implements KeyListener
{
public void keyTyped(KeyEvent e)
{
System.out.println(e.getKeyChar());
}
}
我省略了一些必需的方法,因为它们与我的问题无关。如果我按下一个字母键,它会将字母打印到控制台。但是如果我使用一个键盘组合,比如Ctrl + g,在控制台打印的字符只是一个带有问号的方块。
有办法检测字符是否为“丢失字符”吗?
英文:
When using the KeyTyped
method for the KeyListener
, sometimes I get "missing characters". I'll show the code I use to get them, then ask my question.
public class KeyInput implements KeyListener
{
public void keyTyped(KeyEvent e)
{
System.out.println(e.getKeyChar());
}
}
I left out a few required methods because they are unrelated to my question. If I press a letter, it prints the letter to console. But if I use a key combination, ie. control + g, The character printed to console is just a square with a question mark.
Is there a way to detect if the character is a "missing character"?
答案1
得分: 2
或许您可以使用Font
类的canDisplay(...)
方法。
英文:
Maybe you can use the canDisplay(...)
method of the Font
class.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论