c ++ win32用DirectInput模拟按键

编程入门 行业动态 更新时间:2024-10-27 14:29:09
本文介绍了c ++ win32用DirectInput模拟按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何使用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模拟按键

本文发布于:2023-10-08 13:49:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472817.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按键   DirectInput

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!