如何使用SendInput重复键击? [英] How to repeat key strokes with SendInput?

查看:293
本文介绍了如何使用SendInput重复键击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VC ++中编写一个小工具来记录关键笔划,以便稍后重播它们,一个宏记录器。它的工作相当不错已经使用键盘钩子函数读取每个按键和释放事件。回放与SendInput()函数一起工作,通常也很好 - 除了重复的关键笔划。每次释放后按几次键就没有问题。但是按下它并按住它,对于要重复的输入字符,可以记录,但只能在某些应用程序中重放。有些人接受并输入字符多次,有些只做一次。 (它是可再现的,它是哪个)。宏录音机本身也可以通过它的监听钩子看到在播放过程中按下一个按钮。

I'm writing a little tool in VC++ to record key strokes to replay them later, a macro recorder. It works quite nice already, using a keyboard hook function that reads each and every key press and release event. The playback works with the SendInput() function and generally also works fine - except for repeating key strokes. Pressing a key several times after releasing it every time is no problem. But pressing it and holding it down, for the input character to be repeated, can be recorded but can only be replayed in some applications. Some accept and enter the character multiple times, some do it only once. (It is reproducible which does which.) The macro recorder itself also sees the held down key pressed just a single time during playback, through its monitoring hook.

我可以让SendInput发送单个键的多个后续键击,而不在我自己添加键释放事件之间?

So, how can I make SendInput send multiple subsequent key strokes of a single key without adding key release events on my own in between? Sending a sequence of [press] [press] [press] ... [release] doesn't always work.

推荐答案

发送序列[press] [press] [press] ... [release]您可以在一个SendInput调用中发送多个键,但您仍然需要在每个字符上设置keyup标志,以对每种类型的键击都获得相同的结果。

You could send Multiple keys in one SendInput calls, but you will still need to set keyup flags on every char to get same results on every type of keystrokes.

发送aa,你可以这样做。

if you need to send "aa", you can do like this.

INPUT input[4];

input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = 0;
input[0].ki.wScan = 'a';
input[0].ki.dwFlags = 0;

input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = 0;
input[1].ki.wScan = 'a';
input[1].ki.dwFlags = KEYEVENTF_KEYUP;

input[2].type = INPUT_KEYBOARD;
input[2].ki.wVk = 0;
input[2].ki.wScan = 'a';
input[2].ki.dwFlags = 0;

input[3].type = INPUT_KEYBOARD;
input[3].ki.wVk = 0;
input[3].ki.wScan = 'a';
input[3].ki.dwFlags = KEYEVENTF_KEYUP;

SendInput(4, input, sizeof(INPUT));

这篇关于如何使用SendInput重复键击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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