0

I'm writing an application that performs keyboard hook for Internet Explorer and for other apps. Everything works great except one annoying problem.

In Internet explorer, I change the active language and write in text box of HTML document, say to Hebrew or Arabic, but I keep getting the characters in English in my hooking app.

In the Internet explorer HTML document characters are displayed in the correct language but in the app I keep getting only English.

for example:

When I press"abcאבג" in Internet Explorer, and I get "abctcd" in the hooking app.

When I tried to hook other programs like Word or Excel or Firefox or Chrome, everything worked as expected.

4

2 回答 2

1

我最近用一些代码回答了一个问题,例如:

但是,该答案与您的答案并不直接对应,仅适用于一些示例代码。

您需要注意的是,与 Work 或 Excel 不同,您的挂钩程序可能不知道当前的 IME。因此,您首先需要知道用户切换了 IME,并指定了相应的键盘布局。API ActivateKeyboardLayout可以做到这一点。

在您知道键盘布局后,您可以通过调用ToUnicodeExToAsciiEx来获取挂钩程序中的相应字符HKLActivateKeyboardLayout返回您,它指示特定的键盘布局。

有关概述的详细信息,请参阅MSDN 上的关于键盘输入。

于 2013-04-07T09:58:36.653 回答
0

我怀疑问题更深。

我写了以下代码:

IntPtr handle = new IntPtr(-1);
handle = GetForegroundWindow();
uint tpid = GetWindowThreadProcessId(handle, IntPtr.Zero);
IntPtr hKL = GetKeyboardLayout(tpid);
hKL = (IntPtr)(hKL.ToInt32() & 0x0000FFFF);
lbl1.Content = hKL.ToString();

该问题仅出现在 IE 中(我检查了版本 7、8、9 和 10)并且仅出现在 HTML TextBox 控件中。

在 url 上,一切都按预期工作(就像在所有其他应用程序中一样,例如 word excel firefox、chrome 等),如果我用希伯来语写,会显示 1037 并用希伯来语显示正确的字符,如果我用英文写,会显示 1033 和显示正确的英文字符,如果我开始用希伯来语写,通过英文仍然继续显示正确​​的 hkl 值和正确的字符。

到目前为止还不错。

仅当我在 HTML 文本框中键入时才会出现此问题,然后它才无法识别正确的语言。

当我在 HTML 的文本框中输入时,他识别出正确的语言和正确的第一个字符的 hkl 值,当我更改语言时,他没有识别更改并继续向我发送输入第一个字符的语言字符。

于 2013-04-08T09:05:54.870 回答