windows 在 JavaScript 中获取当前的键盘布局语言
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4402849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get the current keyboard layout language in JavaScript
提问by Rotem
I am using wshShell.SendKeys to input some text into web sites from an HTA, when my current keyboard layout is not English, the results of wshShell.SendKeys is unanticipated.
我正在使用 wshShell.SendKeys 从 HTA 向网站输入一些文本,当我当前的键盘布局不是英文时,wshShell.SendKeys 的结果出乎意料。
I want my function to check rather the language is English, otherwise send ALT+SHIFT to change it to English.. The hard part for me is to find a function that returns the current keyboard layout.
我希望我的函数检查语言是英语,否则发送 ALT+SHIFT 将其更改为英语。对我来说,困难的部分是找到一个返回当前键盘布局的函数。
If anyone is familiar with a way doing it, I will be glad to know..
如果有人熟悉这样做的方法,我会很高兴知道..
Thanks, Rotem
谢谢,罗特姆
回答by Rotem
Ok, I made it with 'Shadow Wizard''s help..
好的,我是在“影子向导”的帮助下完成的。
This is the code, if anyone want to know (=
这是代码,如果有人想知道(=
Thanks!
谢谢!
var lastKeyPressed = 0;
function sendKey()
{
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.SendKeys( 'a' );
}
function getCurLayout()
{
sendKey();
setTimeout("lastKeyLang()",10);
}
function lastKeyLang()
{
if( lastKeyPressed == 97 )
alert( 'EN' );
else
alert( 'HE' );
}
document.onkeypress = saveLastKey;
function saveLastKey()
{
lastKeyPressed = window.event.keyCode;
}
回答by Shadow Wizard is Ear For You
Send "A" to textbox, read it back like this:
将“A”发送到文本框,像这样读回:
nValue = oTextbox.value.charCodeAt(0);
If nValue
is 65 layout is English otherwise it's not and probably ?
was sent instead.
如果nValue
是 65 布局是英语,否则它不是并且可能?
被发送。