简体   繁体   English

Java键输入与KeyEvent的VK键不同

[英]Java key input is different to KeyEvent's VK keys

I'm trying to compare the key code I get from KeyEvent.getKeyCode() from a key listener to something like KeyEvent.VK_SLASH however when I press the slash key (and I know it's slash because it shows a /), the comparison ( if(e.getKeyCode() == KeyEvent.VK_SLASH) ) is false. 我想比较关键的代码,我从拿到KeyEvent.getKeyCode()从按键侦听器,像KeyEvent.VK_SLASH但是当我按斜线键(我知道这是因为斜线它显示了一个/),比较( if(e.getKeyCode() == KeyEvent.VK_SLASH) )为假。

However when I compare it to KeyEvent.VK_DEAD_ACUTE , it returns true. 但是,当我将其与KeyEvent.VK_DEAD_ACUTE进行比较时,它返回true。

Other keys such as ABCD or numbers are fine however some keys such as ` and / are different. 其他键(如ABCD或数字)也可以,但是某些键(如和)则不同。

Why is this? 为什么是这样? And how can I fix this? 我该如何解决呢?

Edit: Other keys such as ' are affected too as it produces a . And pressing the 编辑:诸如'之类的其他键也会受到影响,因为它会产生一个. And pressing the . And pressing the key gives me VK_DEFINED . And pressing the键给我VK_DEFINED

Maybe try using 也许尝试使用

Key = e.getKeyCode();

then do 然后做

if( Key == KeyEvent.VK_SLASH){
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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