6

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

Marco
  • 985
  • 7
  • 22
  • 50

5 Answers5

12

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

MD. Mohiuddin Ahmed
  • 2,092
  • 2
  • 26
  • 35
Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
10

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
wvdz
  • 16,251
  • 4
  • 53
  • 90
3

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.

captainroxors
  • 718
  • 7
  • 18
3

VK_PERIOD should do what you need.

npinti
  • 51,780
  • 5
  • 72
  • 96
0

I am using Java 8 with Apache Netbeans. VK_PERIOD works fine with both decimals and dot.