VkKeyScanEx / Sendinput替代对Unicode的? [英] VkKeyScanEx/Sendinput alternative for unicode?

查看:878
本文介绍了VkKeyScanEx / Sendinput替代对Unicode的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在试图发送一个字符。所以我用的是本地方法GetKeyboardLayout和VkKeyScanExW位于user32.dll中获得来自系统当前的键盘布局的虚拟键代码(SHIFT-和控件状态)。后来我这个虚拟键代码发送到使用从user32.dll中的本地方法SendInput应用

I'm currently trying to send a character. Therefore I use the native methods GetKeyboardLayout and VkKeyScanExW located in user32.dll to get the virtual key code (and shift- and control-state) for the current keyboard-layout from the system. Afterwards I send this virtual keycode to the application using the native method SendInput from user32.dll.

一切工作的优良 - 除了欧元标志。当我通过这个人物作为参数传递给VkKeyScanExW返回-1,这意味着没有找到。在我的键盘是使用Ctrl +菜单+ E(德语布局)位于

Everything work's fine - except of the euro sign. When I pass this character as parameter to VkKeyScanExW it returns -1, which means not found. On my Keyboard it is located using Ctrl+Menu+E (German layout)

现在我认为这是因为欧元符号是Unicode标志,在ASCII没有映射-布局。我读Sendinput还允许使用硬件扫描码一个Unicode模式。所以我希望用SendInput的Unicode模式能解决我的问题。但我想我的virtualkey代码不是硬件扫描码为Unicode范围更广。我在哪里可以找到一个样本如何通过SendInput发送一个Unicode字符(例如€)到另一个控件/窗口。 MSDN和pinvoke.net不提供有用的样品。

Now I assume this occurs because the euro sign is a unicode sign and not mapped in the ascii-layout. I read Sendinput also allows a unicode-mode using a hardware scancode. So I hope using the unicode mode of SendInput will solve my problems. But I guess my virtualkey code is not the hardware scan code as unicode range is wider. Where can I find a sample how to send a unicode character (e.g. €) via SendInput to another control/window. MSDN and pinvoke.net do not provide useful samples.

推荐答案

在我使用SendInput的Unicode参数解决了这个问题其间。现在,我没有使用任何VkKeyScan更多 - 我可以通过人物本身

In the meantime I solved the problem using the unicode parameter of SendInput. Now I don't have to use VkKeyScan any more - I can pass the character itself.

private static void SendUnicodeChar(char input)
{
    var inputStruct = new NativeWinApi.Input();
    inputStruct.type = NativeWinApi.INPUT_KEYBOARD;
    inputStruct.ki.wVk = 0;
    inputStruct.ki.wScan = input;
    inputStruct.ki.time = 0;
    var flags = NativeWinApi.KEYEVENTF_UNICODE;
    inputStruct.ki.dwFlags = flags;
    inputStruct.ki.dwExtraInfo = NativeWinApi.GetMessageExtraInfo();

    NativeWinApi.Input[] ip = { inputStruct };
    NativeWinApi.SendInput(1, ip, Marshal.SizeOf(inputStruct));
}



感谢所有的帮助。

Thanks to all for the help.

这篇关于VkKeyScanEx / Sendinput替代对Unicode的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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