CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2003
    Location
    Greece
    Posts
    533

    use sendmessage api as sendkey to inactive window

    I need badly to send keystrokes to Windows Media Encoder 9, when it is minimized (meaning the window is not active).

    WME is a great program for streaming to a Windows Media Server, but it is a bit unstable for continuous encoding, that is it stops encoding due to some strange errors. Its not our subject here to analyze them.

    The fact is that when pressing the START ENCODING button (hotkey: Ctrl+Shift+E), the encoder starts encoding again without a problem. We cant afford to pay a human to watch the streaming process all the time if something happends.

    I made a simple utility which it sends Ctrl+ShifT+E every one minute, even the encoder encodes OK (the WME has no problem if it accepts the hotkey even when is broadcasting). So we are ok if the process stops: in a minute the utility sends the right hotkey and the process starts ok.

    This works, but the computer has to do some more stuff, meaning I cant have the WME window open and active all the time.

    I read about SendMessage, and I've tried ANY example I've found on the internet

    h = FindWindow(vbNullString, "LIVE - Windows Media Encoder")
    SendMessage h, WM_KeyDown, VK_Control, 0&
    SendMessage h, WM_KeyDown, VK_Shift, 0&
    SendMessage h, WM_KeyDown, VK_E, 0&
    Sleep 300
    SendMessage h, WM_KeyUp, VK_E, 0&
    SendMessage h, WM_KeyUp, VK_Shift, 0&
    SendMessage h, WM_KeyUp, VK_Control, 0&

    The code seems OK, but .. it doesnt work.

    I also tried an example I've found of searching all the child controls in WME's parent window. The loop returns only the scroll bar! So I cant find the button "Start Encoding" in order to send a button click on that control.

    Anyone can help?
    - Better live in the digital world -

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: use sendmessage api as sendkey to inactive window

    Download the SDK for WMP, and you should see how to send it commands without resorting to sendkeys
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2003
    Location
    Greece
    Posts
    533

    Re: use sendmessage api as sendkey to inactive window

    Thank you for the recommendation, I didnt know that there is a SDK for WME. I must do a research on that.

    I still want to know, anyway, if there is a way to send a keystroke (combined or not) to an inactive (minimized or gray) foreign application. I 've tried SendMessage with NotePad too, the same behavior (does nothing). Maybe I am doing something wrong (see my first post code example).

    In old days I loved to use DDE protocol builted in Microsoft Apps, but nowadays DDE is totally ignored (and I think not supported by the OSes anymore) and for sure WME knows nothing about it..
    Last edited by dtv; March 31st, 2009 at 03:38 AM.
    - Better live in the digital world -

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: use sendmessage api as sendkey to inactive window

    I think an inactive or minimized window does not respond to WM_KEYxxx messages.
    A window to respond to these message must be active and have the focus, like being able to receive real keystrokes.

  5. #5
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: use sendmessage api as sendkey to inactive window

    I don't think you can use SendMessage or PostMessage for key combos.
    Use keybd_event or SendInput instead, to create a chain of events.

    If you want to send to minimized or disabled windows, you can detect that first,
    with IsIconic and IsWindowEnabled API's.
    Then undo it, with ShowWindow and EnableWindow.

    I've got a module called SendKeys that does that automatically.
    It's below in my signature.

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