CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2007
    Posts
    132

    how to send capital letters to another window?

    I'm able to search through the windows and find the one I need (Win XP), and I'm able to send keystrokes / letters to another window. However, since the virtual keycodes don't distinguish between upper and lower case, I'm stuck as to how to send upper case letters to another window from my app (i.e. a window that is not part of my app). I have tried using the keybd_event() function to set caps lock which seems to be doing *something*, but there isn't any rhyme nor reason to when it actually decides to set the caps lock...I presume it is done in parallel, so I tried calling sleep() for a sec to make sure it has time to get through, but that isn't working either...how can I go about doing this?

    thanks!

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

    Re: how to send capital letters to another window?

    Try to use SendInput API and send both VK_SHIFT and the letter you want to.
    Victor Nijegorodov

  3. #3
    Join Date
    Oct 2007
    Posts
    132

    Re: how to send capital letters to another window?

    Thanks victor --

    I actually have it working with keybd_event, however, there is a strange synchronization issue where it does not work if the window is not in the foreground. If the window has focus, all is well...? Any idea why?

  4. #4
    Join Date
    Jan 2009
    Posts
    35

    Re: how to send capital letters to another window?

    The keybd_event function acts just as if you had pressed the corresponding keys on the keyboard. Thus, if the window you want to send to is not in focus, the keystrokes will not reach it.

  5. #5
    Join Date
    Oct 2007
    Posts
    132

    Re: how to send capital letters to another window?

    Thanks for your response calc0000 -

    The problem I'm having isn't that the keystrokes don't make it, it's the synchronization of when the caps lock is on and off vs what they are supposed to be. In other words, the sequence of events I have now looks like this:

    turn on caps lock
    print letter
    turn off caps lock

    print a bunch of letters

    turn on caps lock
    print letter
    turn off caps lock


    ...given the above I would expect the output string to look something like:

    "T....sdfsdfsd...bunch of letters.....Y"

    as you can see the first and last letters are caps...instead what I see is:

    "T....sDFSDFSD...BUNCH OF LETTERS....Y"

    ...as you can see the first "s" is still lower case as it should be. This is why I started putting pauses in the code to see if the caps lock just needed more time to switch on, but I'm waiting over a second and it doesn't work. That's when I realized it was working only when the window was in focus.

    Is the problem just that the window won't receive the acknowledgement of the caps lock being turned on until it is given focus? If so, then why does one of the letters properly display, but the rest are wrong? Strange.

    Actually, this gives me another idea. I'll try setting the focus to the window programmatically -- can anyone remind me how to do that? I know, I know, look it up.

  6. #6
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: how to send capital letters to another window?

    Quote Originally Posted by andersod2 View Post
    Actually, this gives me another idea. I'll try setting the focus to the window programmatically -- can anyone remind me how to do that? I know, I know, look it up.
    HWND SetFocus(HWND hWnd) and HWND GetFocus(VOID) could be what you're looking for.

    With regards
    Programartist

  7. #7
    Join Date
    Oct 2007
    Posts
    132

    Re: how to send capital letters to another window?

    Thanks Program Artist.

    Unfortunately, although setting the focus works, it's not solving my problem. It kind of makes sense that Windows would not want the setting of the caps lock to affect characters being sent to an unfocused window, however, I can't seem to override this...I will attempt victor's original suggestion to use sendinput...

    Thanks

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