Java does not produce the correct AltGr key event

I press AltGr in my Java application, but instead of getting 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 right behavior?

Using Java 7 on Windows 7. Can be played using the demo application found at 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
+6
source share
1 answer

in windows, AltGr and Ctrl + Alt are synonyms. in some locales (keyboard layouts?) they are both considered as Ctrl + Alt, while in others they are considered as AltGr. However, I'm not quite sure.

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

+4
source

Source: https://habr.com/ru/post/905562/


All Articles