C++ simulate pressing of equal sign (=) and question mark (?)

痴心易碎 提交于 2019-12-02 16:36:50

问题


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/

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));

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).

Thank you.


回答1:


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.



来源:https://stackoverflow.com/questions/17700129/c-simulate-pressing-of-equal-sign-and-question-mark

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!