C++ problem with sending keystrokes
I'm trying to send keystrokes to another application(so far succesfully) but it wont send the '%', hex value should be 0x25, I have tried multiple times, I'm pretty sure my code is fine so:/. Any way I can send a % anyway?
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
Doomy
I'm trying to send keystrokes to another application(so far succesfully) but it wont send the '%', hex value should be 0x25, I have tried multiple times, I'm pretty sure my code is fine so:
Then what is the problem if your code is fine? Or it is NOT fine since it fails by sending '%' char? :confused:
Quote:
Originally Posted by
Doomy
Any way I can send a % anyway?
Perhaps using SendInput API. :rolleyes:
And, BTW, how are you doing it now?
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
VictorN
Then what is the problem if your code is fine? Or it is NOT fine since it fails by sending '%' char? :confused:
Perhaps using SendInput API. :rolleyes:
And, BTW, how are you doing it now?
The only thing that fails is sending the % char, all other letters numbers and signs(I need atleast) work, I've seen a lot of people use SendInput() but I have yet to find a good explanation of how to use it, can you help me?
I forgot to add I'm using keybd_event now (I know I should be using SendInput but as I stated before I haven't seen anyone use it in a simple way for anyone to understand -.~)
I'm kinda a newby with API
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
Doomy
I've seen a lot of people use SendInput() but I have yet to find a good explanation of how to use it, can you help me?
Just search the Forums for SendInput examples...
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
VictorN
Just search the Forums for SendInput examples...
but that doesnt explain why i cant send a % with keybd_event..
Re: C++ problem with sending keystrokes
Define "cant send a % with keybd_event"
What fails: keybd_event? Or "another application" doesn't react to the '%' sign been sent?
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
VictorN
Define "cant send a % with keybd_event"
What fails: keybd_event? Or "another application" doesn't react to the '%' sign been sent?
A keyboardevent is being sent but its not a %, it seems to be simulating left arrow key or something...
Re: C++ problem with sending keystrokes
And how is it interpreted if you *directly* (via keyboard) "send" % to this application?
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
Doomy
A keyboardevent is being sent but its not a %,
How do you know it?
keybd_event does not return any value (it is void) so it is impossible to know whether it succeeds or fails (note that Sendinput type is int and if it filed then GetLastError will give you the extended error info)
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
VictorN
How do you know it?
keybd_event does not return any value (it is void) so it is impossible to know whether it succeeds or fails (note that Sendinput type is int and if it filed then GetLastError will give you the extended error info)
I had it use an autokey in a textbox with text that was marked, after the keybdevents it wasnt marked anymore and the blinking | was one character from the end instead of the end
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
Doomy
I had it use an autokey in a textbox with text that was marked, after the keybdevents it wasnt marked anymore and the blinking | was one character from the end instead of the end
Let us see the code that calls keybd_event for this character, including the values you're using to call keybd_event.
Regards,
Paul McKenzie
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
Doomy
I had it use an autokey in a textbox with text that was marked, after the keybdevents it wasnt marked anymore and the blinking | was one character from the end instead of the end
Could it be that % sign has some special meaning for this text box?
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
VictorN
Could it be that % sign has some special meaning for this text box?
no i tried putting a % in myself it worked fine
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
Doomy
no i tried putting a % in myself it worked fine
So are we to keep guessing, or are you going to show us your code?
Regards,
Paul McKenzie
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
Paul McKenzie
So are we to keep guessing, or are you going to show us your code?
Regards,
Paul McKenzie
keybd_event(0x25, 0, 0, 0);
keybd_event(0x25, 0, KEYEVENTF_KEYUP, 0);
there, does that help in any way? i doubt it.
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
Doomy
keybd_event(0x25, 0, 0, 0);
keybd_event(0x25, 0, KEYEVENTF_KEYUP, 0);
there, does that help in any way? i doubt it.
Sure it helps.
At least it shows that you are NOT sending '%'. According to MSDN:
Quote:
VK_LEFT 0x25 LEFT ARROW key
Re: C++ problem with sending keystrokes
Good catch, Vlad! :thumb:
Re: C++ problem with sending keystrokes
Quote:
Originally Posted by
Doomy
keybd_event(0x25, 0, 0, 0);
keybd_event(0x25, 0, KEYEVENTF_KEYUP, 0);
there, does that help in any way?
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
Where do you see in the documentation above that 0x25 is the "%" key? The virtual key code you're sending is the left-arrow. So your program behaves exactly as expected.
Secondly, the "%" is a shifted-5 key. So how are you sending the shift-key? I have never used keybd_event, but as you can see, you need to distinguish between a shifted key and non-shifted key.
A bit of advice -- too many times, people believe their code is either not relevant to the problem, or think that their code is OK. Then what winds up happening is that when the code is posted late in the game, we see that the code was not correct. We could have saved a lot of time if you had posted the erroneous code much earlier, preferably in your first post.
Regards,
Paul McKenzie