KeyPressed和KeyTyped混淆 [英] KeyPressed and KeyTyped Confusion

查看:317
本文介绍了KeyPressed和KeyTyped混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了KeyPressedKeyTyped事件之间的区别,但仍然不清楚.我发现的一件事是Keypressed比KeyTyped首先被触发. 请澄清一下这些触发的确切时间.哪个用途适合用于哪个目的? 预先感谢

I have searched about difference between KeyPressedand KeyTyped Events but still I'm not clear about that . One thing I have found is Keypressed is triggered first than KeyTyped . Please clarify me when these are triggered exactly . Which is appropriate to use for which purpose ? Thanks in advance

推荐答案

keyPressed.按下可以转换为Unicode字符的键时,将触发keyTyped.例如,如果按住Shift键,则按"a"会告诉keyTyped您键入了大写字母A,而keyPressed只会得到"a"键,没有大写字母或小写字母.您无法从keyPressed调用event.getKeyChar(),因为没有与事件关联的键字符.字符仅来自keyTyped.

keyPressed is fired whenever any key press occurs. keyTyped is fired when a key is pressed that can be converted into a unicode character. If the shift key is down, for example, pressing "a" will tell keyTyped that you typed a capital A, and keyPressed will just get the "a" key, without capital or lowercase designations. You cannot call event.getKeyChar() from keyPressed, because there is no key char associated with the events. Characters only come from keyTyped.

基本思想是keyTyped用于查找键入的字符,而keyPressed用于获取原始按键.

The basic idea is that keyTyped is used to find characters that are typed, and keyPressed is used for obtain raw key presses.

这篇关于KeyPressed和KeyTyped混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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