SendInput: how use to a window?

the SendInput() works fine for a focus window. but when the window loses the focus, the SendInput() can be used to another window.
so how can i choose the window target for use the SendInput()?
Take a look at this:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms646304%28v=vs.85%29.aspx

msdn wrote:
Synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver's interrupt handler calls the keybd_event function.
That mentioned message is send to the focus window. But you may send it to the other window too. So a combination SendInput() and PostMessage() may help.

Or you set the focus to the target window:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms646312%28v=vs.85%29.aspx
using:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
SetFocus(getwmpwindow);
    // Simulate a key press
         keybd_event( VK_CONTROL,
                      0x45,
                      KEYEVENTF_EXTENDEDKEY | 0,
                      0 );

      // Simulate a key release
         keybd_event( 'M',
                      0x45,
                      0,
                      0);
        // Simulate a key release
         keybd_event( 'M',
                      0x45,
                      0,
                      KEYEVENTF_KEYUP);

         keybd_event( VK_CONTROL,
                      0x45,
                      KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
                      0 );

works fine. but, like, i said, only with window focused :(

"That mentioned message is send to the focus window. But you may send it to the other window too. So a combination SendInput() and PostMessage() may help."
how i do that combination? i don't see any data or on struture with SendInput() for that :(
how i do that combination?
I mean this:
1
2
3
4
5
6
7
8
9
10
11
12
void SendInputkey(HWND window, WORD key, WORD shift=0)
{
    if(shift!=0)
    {
        keybd_event(...shift...);
        SendMessage(window, WM_KEYDOWN,(WPARAM) shift,0); // consider PostMessage()
    }
    keybd_event(...key...);
    SendMessage(window, WM_KEYDOWN,(WPARAM) key,0); // consider PostMessage()

...
}


Another thing you could do is Set/Reset the focus:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
HWND org_hwnd = SetFocus(getwmpwindow);
    // Simulate a key press
         keybd_event( VK_CONTROL,
                      0x45,
                      KEYEVENTF_EXTENDEDKEY | 0,
                      0 );

      // Simulate a key release
         keybd_event( 'M',
                      0x45,
                      0,
                      0);
        // Simulate a key release
         keybd_event( 'M',
                      0x45,
                      0,
                      KEYEVENTF_KEYUP);

         keybd_event( VK_CONTROL,
                      0x45,
                      KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
                      0 );

	SetFocus(org_hwnd); // Note: set the focus back to were it was 
yah. changing the focus will work correctly. but i need without focus :(
What about the combination of messages?
What about reseting the Focus?
in these case, if i change the focus, i can't do anotherthing :(
Last edited on
Topic archived. No new replies allowed.