c++ win32 使用 DirectInput 模拟按键

标签 c++ c winapi directinput

如何使用 DirectInput 模拟按键?我目前有初始化(但我不确定它是否好):

#include <dinput.h>

#pragma comment (lib, "dinput8.lib")
#pragma comment (lib, "dxguid.lib")

LPDIRECTINPUT8 din;    // the pointer to our DirectInput interface
LPDIRECTINPUTDEVICE8 dinkeyboard;    // the pointer to the keyboard device
BYTE keystate[256];    // the storage for the key-information

void initDInput(HINSTANCE hInstance, HWND hWnd);    // sets up and initializes DirectInput
void detect_input(void);    // gets the current input state
void cleanDInput(void);    // closes DirectInput and releases memory 

那么有人可以告诉我如何模拟游戏中的左箭头键按下吗?

最佳答案

发送输入

SendInput让你模拟按键。您可以选择使用虚拟键码或扫描码来识别键(参见 KEYBDINPUT.dwFlags )。显然,DirectInput 会忽略虚拟键码,但会处理扫描码。

简而言之,将 SendInput 与扫描码一起使用,DirectInput 将响应。

拦截

Interception工具包使用内核模式驱动程序和一些用户模式帮助函数模拟按键。

存在一些安全隐患。由于它是一个闭源内核模式驱动程序,您需要完全信任作者。即使作者完全值得信赖,驱动程序也允许监视和创建输入,因此它会打开一个很大的安全漏洞:任何非特权软件都可以使用它来嗅探,例如,提升密码。它还可以阻止键盘输入,包括 CTRL+ALT+DEL。

评论the github page建议它在 Windows 8 中尚不可用。

使用它需要您自担风险。

关于c++ win32 使用 DirectInput 模拟按键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7320424/

相关文章:

c++ - C++中的中断

c++ - 读取内核模式注册表访问?

c - 使用 fork() 进行二分查找

c# - 在 WPF 中将窗口置于最前面

c++ - 如何查看系统是否处于注销状态?

c++ - 需要帮助破译模板元编程宏

c++ - 未解析的外部符号 boost::chrono::system_clock::now(void)

谁能在 DAC 的以下场景中帮助我

android - 蓝牙串口通讯,HC-06模块转安卓手机

windows - 这是一个错误(Windows API)吗?