Frage

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.

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top