So here is my problem , I've been trying to simulate various key events with the sendinput() function, I even wrote functions to simulate complex key events like winkey+D, alt+f4 etc using that function , anyway everything worked fine till I decided to try out the enter key aka return with virtual keycode VK_RETURN as provided by this nice msdn list of VK codes, the thing is that it doesn't work
now, i am guessing that 3 things can be wrong with this enter key ,
the virtual key code for enter and the value that the pc keyboard actually uses are not the same
there is something wrong in the code typos wrong codes , bad calls etc; something i'm not so sure since send input works for the rest of the keys tested so far
the enter, return carriage, return or whatever the superstar of keyboard keys called just doesn't work like the other buttons so my code is not right for it
note: if its the 1 , can you pls enlighten on how do i get the right value of a keycode, programmatically for a given button without relying on static resources like msdn vk list
anyway here is my snippet
i make an input struct like this and assign it as keyboard input
INPUT Keybord;
Keybord.type = INPUT_KEYBOARD;
Keybord.ki.wScan = 0;
Keybord.ki.time = 0;
Keybord.ki.dwExtraInfo = 0;
here i assign a button VK, i use a struct because i simulate complex events too
in this case the the key press simulation function that follows works just fine and a tab is pressed
cndex[38].primary = VK_TAB;
now here is the troublemaker,i assign it this way
cndex[39].primary = VK_RETURN;
here is my key click function , the first call presses the and the second releases it
void Simple_press(int i){
Keybord.ki.wVk = cndex[i].primary;
Keybord.ki.dwFlags = 0;
SendInput(1, &Keybord, sizeof(INPUT));
Keybord.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &Keybord, sizeof(INPUT));
};
another note is that i don't want to use the sendKeys function , its sluggish and it doesn't work for "{ENTER}" argument either
If your app has a window then its possible to use the spy++ tool to see what data the SendInput command is sending and if the target also has a window you can use the same tool to see if and what messages are being sent to it. Its a handy tool for this very purpose - it may help or at least steer you in the right direction as to what's going on.
http://msdn.microsoft.com/en-us/library/aa264396%28v=vs.60%29.aspx