如何使用DirectInput模拟按键?我目前有初始化(但我不知道是好还是不):
How can I simulate a keypress with DirectInput? I currently have the initialization (but I'm not sure is it good or not):
#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有人可以告诉我如何模拟
So can someone show me how to simulate for example the press of the left arrow key in a game?
推荐答案SendInput
SendInput 可让您模拟按键。您可以选择使用虚拟键代码或扫描代码来识别键(请参阅 KEYBDINPUT.dwFlags )。显然,DirectInput忽略虚拟键代码,但会处理扫描代码。
SendInput lets you simulate key presses. You have a choice of identifying keys using either virtual key codes or scan codes (see KEYBDINPUT.dwFlags). Apparently, DirectInput ignores virtual key codes but does process scan codes.
简而言之,使用SendInput和扫描代码,DirectInput会响应。
In short, use SendInput with scan codes and DirectInput will respond.
拦截
拦截工具包使用内核模式驱动程序和一些用户模式帮助程序函数来模拟按键。
The Interception toolkit simulates key presses with a kernel mode driver and some user mode helper functions.
有一些安全担忧。由于它是一个封闭源内核模式驱动程序,你需要完全信任作者。即使作者是完全可信的,驱动程序允许输入被监视和创建,因此它打开了一个很大的安全漏洞:任何没有特权的软件可以使用它来嗅探,例如,高程密码。它还可以阻止键盘输入,包括CTRL + ALT + DEL。
There are some security worries. Since it's a closed-source kernel mode driver you need to completely trust the author. Even if the author is entirely trustworthy the driver allows input to be monitored, as well as created, so it opens a big security hole: any unprivileged software could use it to sniff, for example, elevation passwords. It can also block keyboard input including CTRL+ALT+DEL.
对 github的评论页面表明它在Windows 8中不起作用。
Comments on the github page suggest it doesn't yet work in Windows 8.
使用它自己承担风险。
更多推荐
c ++ win32用DirectInput模拟按键
发布评论