C ++ WIN32模拟重点preSS与DirectInput的 [英] c++ win32 Simulate Keypress with DirectInput

查看:593
本文介绍了C ++ WIN32模拟重点preSS与DirectInput的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以模拟一个关键preSS与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

<一个href=\"http://msdn.microsoft.com/en-gb/library/windows/desktop/ms646310%28v=vs.85%29.aspx\">SendInput可以模拟按键presses。您可以选择使用虚拟按键codeS或扫描codeS标识键的选择(见<一href=\"http://msdn.microsoft.com/en-gb/library/windows/desktop/ms646271%28v=vs.85%29.aspx\">KEYBDINPUT.dwFlags).显然,DirectInput的忽略虚拟键codeS,但确实扫描过程codeS。

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与扫描codeS和DirectInput的会回应。

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

拦截

借助拦截工具包模拟键presses与内核模式驱动程序以及一些用户模式的辅助函数。

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模拟重点preSS与DirectInput的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆