Java不会产生正确的AltGr键事件

Java不会产生正确的AltGr键事件

本文介绍了Java不会产生正确的AltGr键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Java应用程序中按AltGr键,而不是使用密钥代码VK_ALT_GRAPH接收到KeyEvent,我得到两个事件。第一个关键代码为VK_CONTROL,第二个为VK_ALT。



这是正确的行为吗?



使用Java 7可以在



当我按AltGr它报告:

 
KEY PRESSED:
键代码= 17(Ctrl)
扩展修饰符= 128(Ctrl)
动作键? NO
键位置:左
KEY PRESSED:
键代码= 18(Alt)
扩展修饰符= 640(Ctrl + Alt)
动作键? NO
键位置:右
KEY RELEASED:
键代码= 17(Ctrl)
扩展修饰符= 512(Alt)
动作键? NO
键位置:左
KEY RELEASED:
键代码= 18(Alt)
扩展修饰符= 0(无扩展修饰符)
动作键? NO
键位置:右边


解决方案

在Windows,AltGr和Ctrl + Alt同义词。在某些地区(键盘布局)中,它们都被视为Ctrl + Alt,在其他地方,它们都被视为AltGr,但是我并不完全确定。



请参阅,并使用Ctrl-F查找AltGr。


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
解决方案

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.

这篇关于Java不会产生正确的AltGr键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 13:22