Click here to Skip to main content
15,886,810 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
I am making a program for me and my friends to auto login to a game that we play. I can make the program send the keys to the game window, but I can't make it work properly. What I need it to do is take the text from the Username and Password text box and input it to the games Username and Password box. So what I am trying to do is make is send the text from the username text box then hit "TAB" then send the password to the box and press "Enter".

I could really use some help with this! Thank you so much! I am very new to sending keys to other windows and such and I have not been back into programing for a long time. Please excuse my noob status.

The code I have is this so far.

C#
private void button1_Click(object sender, EventArgs e)
{


    // Find The Window Handle For Lineage 2
    IntPtr handle = FindWindow("L2UnrealWWindowsViewportWindow", "Lineage II");
    if (!handle.Equals(IntPtr.Zero))
    {

        // Activate The Lineage 2 Window
        if (SetForegroundWindow(handle))

            // send "Send The TextBox Text To The Lineage 2 Window"
            SendKeys.Send(Username.Text);
            SendKeys.Send("{TAB}");
            SendKeys.Send(Password.Text);
    }
}
Posted

So Sendkeys.Sendwait worked!!! Is there anyway I can do this without the window being active? Like if the game is in the background?
 
Share this answer
 
Try using SendKeys.SendWait instead of Send.

private void button1_Click(object sender, EventArgs e)
        {
 

            // Find The Window Handle For Lineage 2
            IntPtr handle = FindWindow("L2UnrealWWindowsViewportWindow", "Lineage II");
            if (!handle.Equals(IntPtr.Zero))
            {
 
                // Activate The Lineage 2 Window
                if (SetForegroundWindow(handle))
 
                    // send "Send The TextBox Text To The Lineage 2 Window"
                    SendKeys.SendWait(Username.Text);
                    SendKeys.SendWait("{TAB}");
                    SendKeys.SendWait(Password.Text);
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900