对于普通的模拟按键,利用keybd_event等系统函数即可,但是如果要在游戏里面模拟按键,因为部分游戏屏蔽了上述系统api,所以只能使用驱动级按键模拟。
调用KeyPress(73);会模拟按键i。这一小段代码的精妙之处就在于可以绕过绝大部分游戏的检测机制,可谓是外挂利器 :lol:
#include <windows.h>
#include <stdio.h>
#include "winio.h"
void KbcWait4IBE()
{
DWORD dwRegVal=0;
do
{
GetPortVal(0x64,&dwRegVal,1);
}
while(dwRegVal & 0x2);
}
void KeyPress(DWORD KCode)
{
KbcWait4IBE();//Wait for KBC input buffer empty
SetPortVal(0x64,0xD2,1);//Send data back to the system command
KbcWait4IBE();//Wait for KBC input buffer empty
SetPortVal(0x60,MapVirtualKey(KCode,0),1);//Send the key down scancode
Sleep(10);
KbcWait4IBE();//Wait for KBC input buffer empty
SetPortVal(0x64,0xD2,1);//Send data back to the system command
KbcWait4IBE();//Wait for KBC input buffer empty
SetPortVal(0x60,(MapVirtualKey(KCode,0) | 0x80),1);//Send the key up scancode
}
void main()
{
bool bResult;
// Call InitializeWinIo to initialize the WinIo library.
bResult = InitializeWinIo();
if (bResult)
{
Sleep(5000);
printf("supposed key down");
KeyPress(73);
Sleep(5000);
// When you're done using WinIo, call ShutdownWinIo
ShutdownWinIo();
}
else
{
printf("Error during initialization of WinIo.\n");
exit(1);
}
}
调用KeyPress(73);会模拟按键i。这一小段代码的精妙之处就在于可以绕过绝大部分游戏的检测机制,可谓是外挂利器 :lol: