locked
SendMessage for keystroke is not working RRS feed

  • Pergunta

  •  

    Hi all

     

    could you please tell me why this code does not work? It should simulate the pression of TAB and then arrow DOWN, but nothing happens. I´m sure I have the right handle to the window, because I can click with the mouse on some of its buttons.

     

    SetForegroundWindow(hwndWindow);

    SetActiveWindow(hwndWindow);

    SetFocus(hwndWindow);

    SendMessage(hwndWindow, WM_SETFOCUS, VK_TAB, 0);  //tried also without

    SendMessage(hwndWindow, WM_SETFOCUS, VK_TAB, 0);  //these 2 messages

    Sleep(500);

    SendMessage(hwndWindow, WM_KEYDOWN, VK_TAB, 0);

    SendMessage(hwndWindow, WM_KEYUP, VK_TAB, 0);

    Sleep(1000);

    SendMessage(hwndWindow, WM_KEYDOWN, VK_DOWN, 0);

    SendMessage(hwndWindow, WM_KEYUP, VK_DOWN, 0);

     

     

    Many thanks in advance

     

    Fede

    quinta-feira, 8 de maio de 2008 13:38

Todas as Respostas

  • No idea.  SendInput() is another mouse trap.
    sexta-feira, 9 de maio de 2008 01:01
  • Thanks for reply, nobugz.

     

    I tried with SendInput. It works (not on Vista). But since my application runs as a service,  SendInput requires that the service uses Local System Account. This causes conflict with other functionalities, so that´s why I need to use SendMessage or PostMessage.

     

    Can someone else help, please?

    Thanks in advance

     

     

    sexta-feira, 9 de maio de 2008 14:37
  • Hello,
    Please excuse me for being a little off topic:

    For two days I have been suffering, I cannot understand:

    I'm trying to emulate a button click on the Window 10 calculator. Since there are no real buttons of the "Button class" in the calculator, then:
    I look through spy ++ which messages are sent to the calculator window when I click, for example, on the number 8:

    000201C6 S WM_PARENTNOTIFY fwEvent:WM_LBUTTONDOWN xPos:191 yPos:493

    I am sending the same message to the Calculator window:

    HWND calculator_HWND = FindWindowW(NULL, L"Calculator"); //Get HWND calculator
    
    
    WPARAM my_wparam;
    
    
     wchar_t* wchar_wparam = (wchar_t*)&my_wparam;
     wchar_wparam[0] = WM_LBUTTONDOWN;  // LOWORD-left click
     wchar_wparam[1] = 0;   //HIWORD(wParam) is undefined.                                           
    LPARAM my_lparam; //Coordinate click
    
     wchar_t* wchar_laparam = (wchar_t*)&my_lparam;
     wchar_laparam[0] = 191;            //X                                         
     wchar_laparam[1] = 493;            //Y                                      
    SendMessage(calculator_HWND, WM_PARENTNOTIFY, my_wparam, my_lparam);

    After completing the SendMessage, I see a message in the calculator window in SPY ++:

    000201C6 S WM_PARENTNOTIFY fwEvent:WM_LBUTTONDOWN xPos:191 yPos:493

    But the number 8 is not pressed. The calculator does not respond to this message in any way. :(((

    Please tell me what am I doing wrong?


    domingo, 30 de agosto de 2020 19:19
  • Maybe you've forgotten to send WM_LBUTTONUP
    domingo, 30 de agosto de 2020 23:13