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

C# Stimulation mouse / keyboard!

Discussion in 'C#' started by Makaster, Aug 30, 2010.

  1. Makaster

    Makaster New Member

    Joined:
    Aug 30, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello!

    1. I have problem! How i can stimulate keyboard and mouse on No-Active window?
    On active window i use this code:
    Code:
    // Get a handle to an application window.
    [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
    public static extern IntPtr FindWindow(string lpClassName,
    string lpWindowName);

    // Activate an application window.
    [DllImport("USER32.DLL")]
    public static extern bool SetForegroundWindow(IntPtr hWnd);
    &&

    Code:
    	    IntPtr calculatorHandle = FindWindow(null, "MyGame");
    
                // Verify that game is a running process.
                if (calculatorHandle == IntPtr.Zero)
                {
                    MessageBox.Show("Your game is not running!");
                    return;
                }
    
                // Make game the foreground application and send it 
                // a set of calculations.
                SetForegroundWindow(calculatorHandle);
                System.Threading.Thread.Sleep(500);
                SendKeys.SendWait("Hello!");
                System.Threading.Thread.Sleep(500);
                SendKeys.SendWait(" How are");
                System.Threading.Thread.Sleep(1000);
                SendKeys.SendWait(" You");
                System.Threading.Thread.Sleep(200);
                SendKeys.SendWait("?");
    
    But it works only on the active window. When i minimize game i hear 'Beeps - "its: Wrong song - Error ^^"'

    2. How i can stimulate clicked mouse on XYZ position, on Active && no-active window?
     

Share This Page