CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Aug 2011
    Posts
    7

    Angry 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?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by Doomy View Post
    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?

    Quote Originally Posted by Doomy View Post
    Any way I can send a % anyway?
    Perhaps using SendInput API.
    And, BTW, how are you doing it now?
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2011
    Posts
    7

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by VictorN View Post
    Then what is the problem if your code is fine? Or it is NOT fine since it fails by sending '%' char?

    Perhaps using SendInput API.
    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
    Last edited by Doomy; August 7th, 2011 at 10:48 AM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by Doomy View Post
    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...
    Victor Nijegorodov

  5. #5
    Join Date
    Aug 2011
    Posts
    7

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by VictorN View Post
    Just search the Forums for SendInput examples...
    but that doesnt explain why i cant send a % with keybd_event..

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    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?
    Victor Nijegorodov

  7. #7
    Join Date
    Aug 2011
    Posts
    7

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by VictorN View Post
    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...

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: C++ problem with sending keystrokes

    And how is it interpreted if you *directly* (via keyboard) "send" % to this application?
    Victor Nijegorodov

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by Doomy View Post
    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)
    Victor Nijegorodov

  10. #10
    Join Date
    Aug 2011
    Posts
    7

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by VictorN View Post
    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

  11. #11
    Join Date
    Apr 1999
    Posts
    27,449

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by Doomy View Post
    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

  12. #12
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by Doomy View Post
    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?
    Victor Nijegorodov

  13. #13
    Join Date
    Aug 2011
    Posts
    7

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by VictorN View Post
    Could it be that % sign has some special meaning for this text box?
    no i tried putting a % in myself it worked fine

  14. #14
    Join Date
    Apr 1999
    Posts
    27,449

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by Doomy View Post
    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

  15. #15
    Join Date
    Aug 2011
    Posts
    7

    Re: C++ problem with sending keystrokes

    Quote Originally Posted by Paul McKenzie View Post
    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.

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured