请教,C++做一个键盘模拟器,但设置的键在游戏中得不到反映,这个问题要怎么解决?
似乎游戏已屏蔽掉了这种机制的模拟,还有更好的办法吗#include "stdafx.h"
#include "windows.h" void SetNumLock( BOOL bState )
{
BYTE keyState[256];
// GetKeyboardState((LPBYTE)&keyState);
// if( (bState && !(keyState[VK_NUMLOCK] & 1)) ||
// (!bState && (keyState[VK_NUMLOCK] & 1)) )
{
// Simulate a key press
keybd_event( 0x53,
0x1f,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
// Simulate a key release
keybd_event( 0x53,
0x1f,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}
}
void main()
{
int a=5000;
Sleep(a);
SetNumLock( TRUE );
}
似乎游戏已屏蔽掉了这种机制的模拟,还有更好的办法吗#include "stdafx.h"
#include "windows.h" void SetNumLock( BOOL bState )
{
BYTE keyState[256];
// GetKeyboardState((LPBYTE)&keyState);
// if( (bState && !(keyState[VK_NUMLOCK] & 1)) ||
// (!bState && (keyState[VK_NUMLOCK] & 1)) )
{
// Simulate a key press
keybd_event( 0x53,
0x1f,
KEYEVENTF_EXTENDEDKEY | 0,
0 );
// Simulate a key release
keybd_event( 0x53,
0x1f,
KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
0);
}
}
void main()
{
int a=5000;
Sleep(a);
SetNumLock( TRUE );
}
比如:keybd_event(vk,MapVirtualKey(vk,0),dwFlags,NULL);
例如按下 回车键 keybd_event(13, MapVirtualKeyA(13,0), 0, 0);
弹起 keybd_event(13, MapVirtualKeyA(13, 0), KEYEVENTF_KEYUP, 0);13是回车键的 key Value值MapVirtualKeyA 自己百度
建议上驱动Ring0来实现,网上有大把这种教程