填充用于SendInput的HARDWAREINPUT结构的正确方法是什么? [英] What is the proper way to fill a HARDWAREINPUT struct for use with SendInput?

查看:530
本文介绍了填充用于SendInput的HARDWAREINPUT结构的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将WM_KEYDOWN/WM_KEYUP对发送到通常不响应KEYBDINPUT结构的使用的应用程序.我将需要发送转义键以及字母数字字符.由于MSDN仅给出有关使用硬件结构的模糊信息,因此我只能假设uMsg字段用于保存WM_KEYDOWN/WM_KEYUP消息,接下来的两个字段用于lParam的LOWORD和HIWORD(由几位组成,定义扫描代码,密钥是否为重复"等等.

I'm trying to send a WM_KEYDOWN/WM_KEYUP pair to an application which normally does NOT respond to the use of the KEYBDINPUT struct. I will need to send the escape key, as well as alphanumeric characters. As the MSDN only gives vague information on using the hardware struct, I could only assume that the uMsg field is meant to hold WM_KEYDOWN/WM_KEYUP messages, and the the next two fields are for the LOWORD and HIWORD of lParam (composed of several bits which define the scan code, whether or not the key is 'repeating', and so on).

但是在对这些值进行了几个小时的调整之后,我对如何正确模拟硬件击键一无所知.我该怎么做才能使它正常工作?

But after several hours of tweaking around these values, I'm at a total loss on how to correctly simulate a hardware keystroke. What can I do to get this to work?

推荐答案

原来,我没有正确实现KEYBDINPUT,并且还在一次调用SendInput的过程中发送了每个击键.以下内容似乎适用于我的目标应用程序中的标准和扩展虚拟密钥:

Turns out I had implemented KEYBDINPUT improperly, and was also sending each keystroke out in a single call to SendInput. The following appears to work for standard and extended virtual keys in my target application:

VOID SimulateKeystroke(USHORT vk, BOOL bExtended)
{
    INPUT input = {0};

    if(bExtended) input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
    input.ki.wVk  = vk;  
    input.type = INPUT_KEYBOARD;
    SendInput(1, &input, sizeof(input));

    ZeroMemory(&input, sizeof(INPUT));
    input.ki.dwFlags  =  KEYEVENTF_KEYUP;
    if( bExtended ) input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;

    input.ki.wVk = vk;
    input.type = INPUT_KEYBOARD;
    SendInput(1, &input, sizeof(input));
}

这篇关于填充用于SendInput的HARDWAREINPUT结构的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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