简体   繁体   English

无法使用:: SendInput()将退格键发送到写字板应用程序

[英]Could not send backspace key using ::SendInput() to wordpad application

I have used sendinput() function and windows keyboard hooks to develop a custom keyboard for indian languages. 我已经使用sendinput()函数和Windows键盘挂钩为印度语言开发了自定义键盘。 Project is in google code here: http://code.google.com/p/ekalappai 专案位于Google程式码中: http//code.google.com/p/ekalappai

The keyboad hook and sendinput functions are placed in a win32 dll. 键盘挂钩和sendinput函数放置在win32 dll中。 And they are called from a Qt exe. 然后从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. 我无法将Backspace密钥发送到几个应用程序,例如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 完整的dll代码在这里: 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 来自Qt Exe的完整调用代码位于: http : //code.google.com/p/ekalappai/source/browse/trunk/ekalappai/window.cpp

I tried searching in google but could not fine a solution yet. 我尝试在Google中搜索,但无法解决问题。 If anyone has clue on resolving this pls help. 如果有人对解决这个问题有帮助,请帮助。 Thanks. 谢谢。

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. wVk成员是重要的成员,只有虚拟密钥不明确时才使用扫描代码。 Fix: 固定:

kb.wVk   = vk;
kb.wScan = 0;   // TODO: look at VkKeyScanEx()

The documentation says: 该文件说:

If KEYEVENTF_UNICODE is specified, SendInput sends a WM_KEYDOWN or WM_KEYUP message to the foreground thread's message queue with wParam equal to VK_PACKET. 如果指定了KEYEVENTF_UNICODE,则SendInput将WParam等于VK_PACKET的WM_KEYDOWN或WM_KEYUP消息发送到前台线程的消息队列。 Once GetMessage or PeekMessage obtains this message, passing the message to TranslateMessage posts a WM_CHAR message with the Unicode character originally specified by wScan. 一旦GetMessage或PeekMessage获得此消息,将消息传递给TranslateMessage就会发布WM_CHAR消息,该消息带有wScan最初指定的Unicode字符。

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. 只是一个猜测,但是文字处理程序可能会触发WM_KEYDOWN / WM_KEYUP消息而不是WM_CHAR消息的退格行为。 Thus they may be expecting VK_BACKSPACE (not VK_PACKET) as the wParam of those messages. 因此,他们可能期望VK_BACKSPACE(而不是VK_PACKET)作为那些消息的wParam。 It might even be done with accelerators based on VKEYs not characters...heck, you're on Windows, so pretty much anything is possible. 甚至可以使用基于VKEY而不是字符的加速器来完成...哎呀,您在Windows上,所以几乎所有可能。 :) :)

Have you tried not using KEYEVENTF_UNICODE, and doing kb.wVk = VK_BACKSPACE ? 您是否尝试过不使用KEYEVENTF_UNICODE并执行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.) (此外,您可以使用Spy ++更好地了解将哪些关键消息发送到目标应用程序,以及与击中文字退格键时的区别。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM