丢失的按键事件字符

huangapple go评论71阅读模式
英文:

Missing Character For KeyEvent

问题

使用KeyListenerKeyTyped方法时,有时候我会得到“丢失字符”的问题。我将展示我用来获取字符的代码,然后提出我的问题。

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.

huangapple
  • 本文由 发表于 2020年9月27日 07:59:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/64083572.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定