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

    Need help understanding something

    ok here is exactly what Im trying to do,

    I have to insert 10 strings in 10 different textboxes in the shortest possible time (half a second counts), so I thought the best way is to store them all in a program before the timer starts and then simply press TAB 10 times when the timer starts, and my application would paste them each in a separate text box...
    so I want it to paste it on the old focused control then move to the other control ...
    After help of some friends, I got this code
    Code:
    #include <windows.h>
    #include <stdio.h>
    int WINAPI WinMain (HINSTANCE hThisInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR lpszArgument,
                         int nFunsterStil)
    
    {
    HWND hWnd;
        for(;;)
        {
            MSG Msg;
            while(GetMessage(&Msg, NULL, 0, 0)){
                if(Msg.message == WM_KEYUP && Msg.wParam == VK_TAB){
                    PostMessage(Msg.hwnd, WM_PASTE, 0, 0);
                    printf("K\n"); //Never shows this == not entering the if statment ... why ?
                    // you might need to try GetFocus() instead of Msg.hwnd
                }              
                if(!IsDialogMessage(hWnd, &Msg)){
                    TranslateMessage(&Msg);
                    DispatchMessage(&Msg);
                }
            }
        }
        return 0;
    }
    the code is never entering the If statment, even when I press TAB
    I tried adding printf("test\n"); to check, it never shows

    why is it not entering the If Statment ?

  2. #2
    Join Date
    Jun 2008
    Posts
    592

    Re: Need help understanding something

    It is because getmessage isn't going to work because you have no windows at all. You need a window. Are you trying to get keys from other windows that don't belong to your thread?
    Last edited by Joeman; June 3rd, 2010 at 02:33 PM.

  3. #3
    Join Date
    Jun 2008
    Posts
    3

    Re: Need help understanding something

    Im trying to catch TAB key anywhere, and when it is pressed, I want to paste.
    how can I create a window ... could you show me an example please?
    thx

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Need help understanding something

    Try CreateWindow at MSDN

  5. #5
    Join Date
    Jun 2008
    Posts
    3

    Re: Need help understanding something

    I dont want to create any text box ... I want to capture the tab press where ever it is pressed (my case on a website running by firefox) and when the tab is pressed I want to paste the clipboard and move to the next text box...

    how can I do this? should I create a window or not ?

  6. #6
    Join Date
    Jun 2008
    Posts
    592

    Re: Need help understanding something

    No, you don't want to create a window. You want to capture the system keys and not local keys that are for your thread. The easiest way is to use getasynckeystate, wait for the key to be pressed, wait for it to be released and do what you want. The other method which is more promising is to use a system hook on the keyboard. I could just post source code to do this, but it seems like you haven't even tried to solve this yourself, so look up what I provided and come back Also I am not for sure you can use sendmessage to firefox and it would work, but it may work. One more thing, why not create a firefox plugin?

    If you want to use the system hook on the keyboard, search it on this forum. I just went over this for someone

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Need help understanding something

    Look into the Active Accessibility interfaces. They will allow you to reliable insert text into controls of a web page. As long as the control has a unique tag id, AA will be able to manipulate it even if the control gets moved around on the web page.

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