How to make a function for keystrokes

I have the following code, all I am trying to do is to pass down a keystroke to this function so that it does the keystroke. How do I use a variable of some kind in the function? I know a char doesn't work.

thanks!


void send(char a)
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;

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

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

}
closed account (48bpfSEw)
I know, it's not the direct answer to your question. Hope you can find it out with autoit

https://www.autoitscript.com/autoit3/docs/functions/Send.htm

Please use code tags.
http://www.cplusplus.com/articles/jEywvCM9/

 
ip.ki.wVk = a;

requires a virtual key code, not a character.
https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx

Luckily for us, the virtual key code for the character 'A' is the same as the ASCII code for 'A'.
http://www.ascii-code.com/

Thus, all you need to do is make the character uppercase through the use of the toupper function.
http://www.cplusplus.com/reference/cctype/toupper/
Topic archived. No new replies allowed.