在JavaScript中获取当前的键盘布局语言 [英] Get the current keyboard layout language in JavaScript

查看:150
本文介绍了在JavaScript中获取当前的键盘布局语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用wshShell.SendKeys从HTA向网站输入一些文本,当我当前的键盘布局不是英文时,wshShell.SendKeys的结果是意料之外的。

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.

我希望我的函数检查语言是英语,否则发送ALT + SHIFT将其更改为英语..对我来说很难找到一个返回当前键盘布局的函数。

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.

如果有人熟悉这种做法,我会很高兴知道..

If anyone is familiar with a way doing it, I will be glad to know..

谢谢,
Rotem

Thanks, Rotem

推荐答案

好的,我是通过'Shadow Wizard'帮助制作的..

Ok, I made it with 'Shadow Wizard''s help..

这是代码,如果有人想知道(=

This is the code, if anyone want to know (=

谢谢!

    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;
}

这篇关于在JavaScript中获取当前的键盘布局语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆