1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Sending Simultaneous Keystrokes to Non-Active Window

Discussion in 'C#' started by Lokked, Aug 29, 2010.

  1. Lokked

    Lokked New Member

    Aug 29, 2010
    Likes Received:
    Trophy Points:
    Hello all,

    I am using C# 3.5

    I would like to add Key Sending functionality similar to AutoHotkey to an application of mine for the purposes of automation.

    More specifically, I would like to be able to send multiple, simultaneous keypresses to multiple applications which are NOT the active window.

    Specific Example: I want to send E and S (at the same time) to 3 applications in the background without giving them Keyboard Focus (so I can do other things with another application). I know this is possible because AutoHotkey is capable of this.

    The only information I seek is which win32 APIs I would use to accomplish this. I'm capable of figuring out how to use them.

    This is what I've tried so far, none of which has worked, most likely just for the particular application I'm sending keystrokes to:

    Send/PostMessage() - This is fine for sending a single VK, but it cannot handle sending a request to hold down 2+ VKs. The second+ message will override the previous message.

    SendInput()/SendKeys() - Can only send to the active window, unless I've missed a workaround somewhere.

    AttachThreadInput() - This might be necessary for what I need to do, but does not help my situation with my current knowledge. I tried this along with SetFocus() + SendInput(), but I know there is a more efficient way of doing what I want. The flickering I get is not desirable, nor can I work on other things while my program does its business.

    I thank you for any help in enlightening me as to what APIs I should be using to accomplish my task.


Share This Page