C#自动登录应用程序 [英] C# Auto Login Application
问题描述
我正在为我和我的朋友制作一个程序,以自动登录到我们玩的游戏.我可以使程序将键发送到游戏窗口,但不能使其正常运行.我需要做的是从用户名和密码"文本框中获取文本,并将其输入到游戏的用户名和密码"框中.所以我要做的是make从用户名文本框中发送文本,然后单击"TAB",然后将密码发送到框中,然后按"Enter".
我真的可以为此提供一些帮助!太感谢了!我对将键发送到其他窗口是非常陌生的,而且很长一段时间都没有回到编程方面.请原谅我的菜鸟状态.
到目前为止,我已经拥有了代码.
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.
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);
}
}
推荐答案
因此,Sendkeys.Sendwait起作用了!!!无论如何,在不激活窗口的情况下我可以做到这一点吗?就像游戏在后台一样?
So Sendkeys.Sendwait worked!!! Is there anyway I can do this without the window being active? Like if the game is in the background?
尝试使用SendKeys.SendWait而不是Send.
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);
}
}
这篇关于C#自动登录应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!