键盘模拟技术是在编写游戏外挂时经常使用的技术。但是由于很多游戏采用了directinput的方式,使得发送的一般键盘消息无法被程序收到。这时候需要使用驱动级的键盘模拟技术,直接发送键盘的硬件扫描码,达到模拟键盘的目的。
目前网络上流行的做法是使用winio模拟键盘硬件扫描码,但是winio并不稳定,时常有严重错误发生。这里电王介绍一种稳定方便的方式——使用keybd_event函数,这种方法非常简单,而且极为稳定。
参阅MSDN,我们可以发现以下介绍:
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // flags specifying various function options
DWORD dwExtraInfo // additional data associated with keystroke
);
Parameters
bVk
Specifies a virtual-key code. The code must be a value in the range 1 to 254.
bScan
Specifies a hardware scan code for the key.
dwFlags
A set of flag bits that specify various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags. Value M