【发布时间】:2011-09-06 13:09:53
【问题描述】:
如何使用 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
那么谁能告诉我如何在游戏中模拟例如按下左箭头键?
【问题讨论】:
-
我是否理解正确:您想为不属于您的游戏模拟键盘和鼠标输入?
-
是的,对...就像绑定一样。我的意思是,例如,如果您按 Y,当我按键盘上的 Shift+Q 时,它应该做同样的事情。 KeyPress() 和 keybd_event() 不起作用,这就是我需要使用 DirectInput 的原因。
-
DirectInput 已被弃用,keybd_event() 也是如此。您是否尝试过使用 SendInput()?虽然我可以想象,当另一个程序获得焦点时,问题不仅在于发送输入,还在于接收它。
-
抱歉,在我之前的评论中的“KeyPress()”下,我想说的是 SendInput()。输入已发送,例如它可以写入游戏的字符,但在主屏幕中没有任何反应。
-
问题的答案是“您无法使用 DirectInput 生成输入。DirectInput 用于接收输入,而不是注入它。”
标签: c++ c winapi directinput