Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

keyevent

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

like image 767
Marco Avatar asked Dec 05 '11 12:12

Marco


4 Answers

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

like image 54
Ernest Friedman-Hill Avatar answered Nov 17 '22 11:11

Ernest Friedman-Hill


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
like image 44
wvdz Avatar answered Nov 17 '22 10:11

wvdz


VK_PERIOD should do what you need.

like image 27
npinti Avatar answered Nov 17 '22 10:11

npinti


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.

like image 3
captainroxors Avatar answered Nov 17 '22 12:11

captainroxors