I want to simulate keyboard presses in C++ using SendInput, while single buttons work, trying to send keys simultaneously (shortcuts) doesn't work.
I tried everything, but nothing works, if I send VK_LWIN alone it shows up, but couldn't combine keys simultaneously.
here's my code:
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
void setInput(INPUT * inp,uint index, WORD keycode,BOOL kUp);
void showRun();
int main(void)
{
showRun();
return 0;
}
void setInput(INPUT * inp,uint index, WORD keycode,BOOL kUp)
{
inp[index].type = INPUT_KEYBOARD;
inp[index].ki.wVk = keycode;
inp[index].ki.wScan = MapVirtualKey(keycode, 0);
inp[index].ki.time = 0;
inp[index].ki.dwExtraInfo = 0;
if (kUp == 1)
{
inp[index].ki.dwFlags = KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY;
}else
{
inp[index].ki.dwFlags = 0 | KEYEVENTF_EXTENDEDKEY;
}
}
//this doesn't do anything
void showRun()
{
INPUT *inp = (INPUT*) malloc(sizeof(INPUT) * 4);
memset(inp,0,sizeof(INPUT));
setInput(inp,0,VK_LWIN,0);
setInput(inp,1,VK_RBUTTON,0);
setInput(inp,2,VK_RBUTTON,1);
setInput(inp,3,VK_LWIN,1);
SendInput(4,inp,sizeof(INPUT));
free(inp);
}
while this works fine:
void showStart()
{
INPUT *inp = (INPUT*) malloc(sizeof(INPUT) * 2);
memset(inp,0,sizeof(INPUT));
setInput(inp,0,VK_LWIN,0);
setInput(inp,1,VK_LWIN,1);
SendInput(2,inp,sizeof(INPUT));
free(inp);
}
Thanks in advance for any tip.
Ah stupid me, I should've used VkKeyScan('r') rather than VK_RBUTTON now it works!