【发布时间】:2015-01-30 07:49:41
【问题描述】:
在 Windows 上,我想获取在 Windows 语言栏中看到的代码。我需要在任何给定时间获取当前的键盘布局。
如果我在一个线程中使用它:
InputContext is = InputContext.getInstance();
System.out.println(is.getLocale());
我将获得程序启动时处于活动状态的布局。但是当我按下 win+空格键或 alt+shift 并将布局更改为其他内容时,线程将继续输出以前的语言。
我也没有在系统属性中找到任何可以反映键盘布局的参数。
线程示例:
Thread t = new Thread() {
@Override
public void run() {
while(true) {
InputContext is = InputContext.getInstance();
System.out.println(is.getLocale());
Properties p = System.getProperties();
System.out.println(System.getProperty("user.language"));
try {
sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(InputContextTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
};
t.run();
【问题讨论】:
-
为什么需要这个?在 X11 实现(例如 Linux)上,键盘布局可以随时更改!
-
查看MappingNotify X11 事件
-
但我不关心X11。我需要它在窗户上。我想获取我在 Windows 语言栏中看到的代码。就是这样。
-
那么你应该编辑你的问题来告诉你
-
那应该是JNI没问题或者可能是存储在Windows寄存器中的(stackoverflow.com/questions/62289/…)
标签: java windows locale keyboard-layout