C ++模拟按下等号(=)和问号(?) [英] C++ simulate pressing of equal sign (=) and question mark (?)

查看:53
本文介绍了C ++模拟按下等号(=)和问号(?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在模拟等号(=)和问号(?)的按键时遇到一些问题.我发现如果这两个都没有虚拟按键代码,则应该像这个人使用Ctrl-V一样组合按键和释放键:

Having some problems with simulating a keypress of equal sign (=) and question mark (?). I figured if there's no virtual key code for those two, I should combine key presses and releases as this guy did with Ctrl-V: http://batchloaf.wordpress.com/2012/10/18/simulating-a-ctrl-v-keystroke-in-win32-c-or-c-using-sendinput/

我的"=(SHIFT +" +)代码:

my code for "=" (SHIFT + "+"):

INPUT ip;

ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0; // hardware scan code for key
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;

ip.ki.wVk = VK_LSHIFT;
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));

// Press the "+" key
ip.ki.wVk = VK_OEM_PLUS;
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));

// Release the "+" key
ip.ki.wVk = VK_OEM_PLUS;
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));

// Release the "Shift" key
ip.ki.wVk = VK_LSHIFT;
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));

它输出"+"号.我需要它来工作,最好是任何Windows操作系统,但至少是Windows XP(不确定是否会有所作为).

it outputs the "+" sign. I need it to work on, preferably any windows OS, but at least Windows XP (not sure if it makes a difference).

谢谢.

推荐答案

= 字符是 = / + 键,而 + 是大写字符.因此,要输出等号,只需使用(错误命名的) VK_OEM_PLUS 虚拟键码即可.

The = character is the non-capitalized character on the =/+ key, while + is the capitalized character. Thus, to output an equals sign, simply use the (badly named) VK_OEM_PLUS virtual key code.

这篇关于C ++模拟按下等号(=)和问号(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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