Results 1 to 5 of 5

Thread: Keep focus while sending keys

  1. #1

    Thread Starter
    Fanatic Member TTn's Avatar
    Join Date
    Jul 2004
    Posts
    708

    Question Keep focus while sending keys

    What are some ways to retain focus on an application, while using the sendkeys statement?
    The application has been started with an appactivate (appid).

  2. #2
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575
    Don't use sendkeys use sendmessage like this:

    Private Const WM_IME_CHAR = &H286
    mTargetHwnd = text1.hwnd
    SendMessage mTargetHwnd, WM_IME_CHAR, Asc(sCharacter), 0

    If you want to send Alts and Ctrl just use spy++ to monitor what is been sent to a test app.

    Rob
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

  3. #3

    Thread Starter
    Fanatic Member TTn's Avatar
    Join Date
    Jul 2004
    Posts
    708

    ?

    Yes, I am using Alt ie, %(f+x){Tab} etc.
    Do I send the same string?
    How will spy++ help me, or would I have to add alot of code?

  4. #4
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575
    If you need to send teh following:

    CTRL + A
    SendMessage mTargetHwnd, WM_CHAR, Asc(LCase$("A")) - 96, 0

    A:
    SendMessage mTargetHwnd, WM_IME_CHAR, Asc("A"), 0

    Enter:
    SendMessage mTargetHwnd, WM_CHAR, VK_RETURN, 0

    Tab:
    SendMessage mFormHwnd, WM_IME_KEYDOWN, VK_TAB, 0

    Shift + Tab is a little more tricky:
    SetForegroundWindow mFormHwnd
    keybd_event VK_SHIFT, 0, 0, 0 'press shift
    keybd_event VK_TAB, 0, 0, 0 'press tab
    keybd_event VK_SHIFT, 0, 2, 0 'release shift


    Spy ++ looks at what messages are sent to a window - almost everything you do can be done in either a sendmessage or a postmessage - with spy ++ you can see these messages and use the functions to send them yourself.

    If the code needs too much changing you might aswell stay with sendkeys. Before each sendkeys statement do a SetForegroundWindow me.hwnd to stay focused.
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

  5. #5
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

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