0

I am trying to send keystrokes to inactive Window (VLC Media Player). I am using C++

Below is the code I tried:

HWND hwndWindowTarget;

HWND hwndWindowVLC = FindWindow(NULL, L"VLC media player");
if (hwndWindowVLC)
{
    // Find the target class window within VLC.
    hwndWindowTarget = FindWindowEx(hwndWindowVLC, NULL, L"QWidget", NULL);
    if (hwndWindowTarget)
    {
        PostMessage(hwndWindowTarget, WM_CHAR, 'P', 0);
    }
}

It works well for Notepad. I do not know what's wrong. Most possibly is because of the window target name on the findwindowex.

I had used WinSpy++ to get the class name of VLC:

image

Please help me. Should you know what's wrong or what could be the name of the correct class window name for VLC, please give me a hint. Many thanks!

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Raymond
  • 604
  • 1
  • 9
  • 27

1 Answers1

0

The VLC window does not have a child window whose classname is QWidget, so FindWindowEx() will fail and return NULL. The VLC window itself is a QWidget class (WinSpy++ tells you as much), so try this instead:

HWND hwndWindowVLC = FindWindow(L"QWidget", L"VLC media player");
if (hwndWindowVLC)
{
    PostMessage(hwndWindowVLC, WM_CHAR, 'P', 0);
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I tried your suggestion but it does not work. It doesn't send anything to VLC – Raymond Nov 28 '13 at 15:44
  • @Raymond: what is the purpose of sending a `'P'` to VLC to begin with? What is the intended goal? I have VLC installed, but it does not do anything when I type a `'P'` on the keyboard, so what are you trying to accomplish? – Remy Lebeau Nov 28 '13 at 19:09
  • I am trying to do a 'Previous' by pressing 'P' on the keyboard it would trigger such event. – Raymond Nov 28 '13 at 21:54
  • Have WinSpy watch the window messages being sent/posted to VLC and see exactly which messages are being sent/posted to which windows (VLC has more than one) and then replicate those messages in code. The FindWindow/Ex() calls you have shown so far does not match what I see in Spy++. And there are more messages involved in keystrokes than just WM_CHAR, such as WM_KEYDOWN/UP. – Remy Lebeau Nov 29 '13 at 04:20