Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java does not produce proper AltGr key event

I'm pressing the AltGr key in my Java application, but instead of receiving a KeyEvent with key code VK_ALT_GRAPH I get two events. The first with key code VK_CONTROL and the second with VK_ALT.

Is this the correct behaviour?

Using Java 7 on Windows 7. Can be reproduced with the demo app found on http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html

When I press AltGr it reports:

KEY PRESSED:
  key code = 17 (Ctrl)
  extended modifiers = 128 (Ctrl)
  action key? NO
  key location: left
KEY PRESSED:
  key code = 18 (Alt)
  extended modifiers = 640 (Ctrl+Alt)
  action key? NO
  key location: right
KEY RELEASED:
  key code = 17 (Ctrl)
  extended modifiers = 512 (Alt)
  action key? NO
  key location: left
KEY RELEASED:
  key code = 18 (Alt)
  extended modifiers = 0 (no extended modifiers)
  action key? NO
  key location: right
like image 729
Markus Kramer Avatar asked Jan 09 '12 21:01

Markus Kramer


1 Answers

in windows, AltGr and Ctrl+Alt are Synonyms. in some locales(keyboard layouts?, they are both treated as Ctrl+Alt, in others, they are both treated as AltGr. However, I am not completely sure.

See http://msdn.microsoft.com/en-us/library/windows/desktop/aa511502.aspx and use Ctrl-F to find AltGr.

like image 133
Jakob Weisblat Avatar answered Oct 10 '22 05:10

Jakob Weisblat