What is the java keyevent field for dot '.'?

陌路散爱 提交于 2019-12-10 17:14:54

问题


I know how to call 1 using keyevent which should be like aaa.keyPress(KeyEvent.VK_1);

Now I need to type (.) dot? But I could not find (KeyEvent.VK_DOT) or some similar command. Please help

Thanks


回答1:


The "dot" is called a period; hence it's VK_PERIOD.




回答2:


Very old question, very basic question, but the correct answer is missing.

For regular dot use:

KeyEvent.VK_PERIOD

For numpad dot use:

KeyEvent.VK_DECIMAL



回答3:


VK_PERIOD should do what you need.




回答4:


VK_PERIOD WILL NOT get it done, by the way. Sometimes the "painfully obvious" answer doesn't quite work.

VK_PERIOD DOES NOT pick up the numpad's dot. It gets the main period, but you're left wonder why it no worky for numpad.

In case you need to respect numpad's dot (which is a strong possibility for all conceivable uses of a dot) you'll have to go with

keyEvent.getKeyChar() == '.'

Or (if you must have your KeyCodes)

keyEvent.getKeyCode() == KeyEvent.VK_PERIOD || keyEvent.getKeyCode() == KeyEvent.VK_DECIMAL

will also work.



来源:https://stackoverflow.com/questions/8384996/what-is-the-java-keyevent-field-for-dot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!