无法使用 ::SendInput() 将退格键发送到写字板应用程序
我使用 sendinput() 函数和 Windows 键盘挂钩来开发印度语言的自定义键盘。 项目位于 Google 代码中:http://code.google.com/p/ekalappai
键盘挂钩和 sendinput 函数放置在 win32 dll 中。它们是从 Qt exe 调用的。 我们的应用程序适用于大多数按键和应用程序。我发现以下问题:
我无法将 Backspace 键发送到 Wordpad/Openoffice/MsOffice 等少数应用程序。我发现箭头键和删除键有同样的问题。
这是我的代码:
extern "C" __declspec(dllexport) void GenerateKey(int vk , bool bExtended)
{
//update previous characters
previous_2_character = previous_1_character;
previous_1_character = vk;
KEYBDINPUT kb={0};
INPUT Input={0};
//keydown
kb.wVk = 0;
kb.wScan = vk;/*enter unicode here*/;
kb.dwFlags = KEYEVENTF_UNICODE; // KEYEVENTF_UNICODE=4
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));
//keyup
kb.wVk = 0;
kb.wScan = vk;/*enter unicode here*/;
kb.dwFlags = KEYEVENTF_UNICODE|KEYEVENTF_KEYUP; //KEYEVENTF_UNICODE=4
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));
}
完整的 dll 代码在这里: http://code.google.com/p/ekalappai/source/browse/trunk/ekhook/ekhook/dllmain.cpp
调用代码:
generatekey = (GenerateKey) myLib->resolve( "GenerateKey" );
generatekey(44,FALSE); //comma - THis works in wordpad/MsOffice/Openoffice
generatekey(2949,FALSE); //tamil character "a" works in Wordpad/Msoffice/Openoffice
generatekey(8,FALSE); //backspace - This is NOT working in Wordpad/Msoffice/Openoffice
Qt Exe 的完整调用代码如下: http://code.google.com/p/ ekalappai/source/browse/trunk/ekalappai/window.cpp
我尝试在谷歌中搜索,但还无法找到解决方案。如果有人有解决此问题的线索,请提供帮助。谢谢。
I have used sendinput() function and windows keyboard hooks to develop a custom keyboard for indian languages.
Project is in google code here: http://code.google.com/p/ekalappai
The keyboad hook and sendinput functions are placed in a win32 dll. And they are called from a Qt exe.
Our application works fine for most keys and applications. I find the following issue:
I could not send Backspace key to few applications like Wordpad/Openoffice/MsOffice. I find same issue with Arrowkeys and delete keys.
Here is my code:
extern "C" __declspec(dllexport) void GenerateKey(int vk , bool bExtended)
{
//update previous characters
previous_2_character = previous_1_character;
previous_1_character = vk;
KEYBDINPUT kb={0};
INPUT Input={0};
//keydown
kb.wVk = 0;
kb.wScan = vk;/*enter unicode here*/;
kb.dwFlags = KEYEVENTF_UNICODE; // KEYEVENTF_UNICODE=4
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));
//keyup
kb.wVk = 0;
kb.wScan = vk;/*enter unicode here*/;
kb.dwFlags = KEYEVENTF_UNICODE|KEYEVENTF_KEYUP; //KEYEVENTF_UNICODE=4
Input.type = INPUT_KEYBOARD;
Input.ki = kb;
::SendInput(1,&Input,sizeof(Input));
}
Full dll code is here: http://code.google.com/p/ekalappai/source/browse/trunk/ekhook/ekhook/dllmain.cpp
Calling code:
generatekey = (GenerateKey) myLib->resolve( "GenerateKey" );
generatekey(44,FALSE); //comma - THis works in wordpad/MsOffice/Openoffice
generatekey(2949,FALSE); //tamil character "a" works in Wordpad/Msoffice/Openoffice
generatekey(8,FALSE); //backspace - This is NOT working in Wordpad/Msoffice/Openoffice
Full calling code from Qt Exe is here:
http://code.google.com/p/ekalappai/source/browse/trunk/ekalappai/window.cpp
I tried searching in google but could not fine a solution yet. If anyone has clue on resolving this pls help. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您混淆了虚拟键和扫描码。 wVk成员是重要的成员,只有虚拟键不明确时才会使用扫码。使固定:
You are mixing up the virtual key and the scan code. The wVk member is the important one, the scan code will only be used it the virtual key is ambiguous. Fix:
文档说:
只是猜测,但文字处理程序可能会触发 WM_KEYDOWN/WM_KEYUP 消息的退格行为,而不是 WM_CHAR。因此,他们可能期望 VK_BACKSPACE (不是 VK_PACKET)作为这些消息的 wParam。它甚至可以通过基于 VKEY 而不是字符的加速器来完成……哎呀,你在 Windows 上,所以几乎一切皆有可能。 :)
您是否尝试过不使用 KEYEVENTF_UNICODE 并执行
kb.wVk = VK_BACKSPACE
?(此外,您还可以使用 Spy++ 来更好地了解哪些关键消息发送到目标应用程序以及它与按文字退格键时有何不同。)
The documentation says:
Just a guess, but the word processing programs might be triggering the backspace behavior off of WM_KEYDOWN/WM_KEYUP messages and not WM_CHAR. Thus they may be expecting VK_BACKSPACE (not VK_PACKET) as the wParam of those messages. It might even be done with accelerators based on VKEYs not characters...heck, you're on Windows, so pretty much anything is possible. :)
Have you tried not using KEYEVENTF_UNICODE, and doing
kb.wVk = VK_BACKSPACE
?(Also, you might use Spy++ to get a better clue of what key messages are sent to the target application and how it differs from when you hit a literal backspace.)