开发者

c++ win32 Simulate Keypress with 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 DirectI开发者_如何学JAVAnput
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 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.

In short, use SendInput with scan codes and DirectInput will respond.

Interception

The Interception toolkit simulates key presses with a kernel mode driver and some user mode helper functions.

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.

Comments on the github page suggest it doesn't yet work in Windows 8.

Use it at your own risk.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜