我的想法是做一个程序,实现YY一键登录,但是想YY程序发送{enter}的时候YY不登录,大神帮我看看是怎么回事啊 ,我打开YY的时候点击ENTER键时是登录的快捷键。。程序图片:
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace YYHelper
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
//此处用于取得窗口句柄
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern int FindWindow(string lpClassName,string lpWindowName); //将窗口设置在最前
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter,int X,int Y,int cx,int cy,int uFlags); //将窗口设置在最前
public static void SetWindowPos(IntPtr hWnd)
{
SetWindowPos(hWnd, -1, 0, 0, 0, 0, 3);
}
//IntPtr iptr = new IntPtr(FindWindow(null, "YY5.3"));
private void btnSend_Click(object sender, EventArgs e)
{
IntPtr iptr = new IntPtr(FindWindow(null, "YY5.3"));
if (iptr==IntPtr.Zero)
{
MessageBox.Show("没找到");
return;
}
else
{
SetWindowPos(iptr);
SendKeys.Send("qq970262810");
SendKeys.Send("{tab}");
SendKeys.Send("A106116a");
SendKeys.Send("enter");
}
}
}
}sendkeys
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace YYHelper
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
//此处用于取得窗口句柄
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern int FindWindow(string lpClassName,string lpWindowName); //将窗口设置在最前
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter,int X,int Y,int cx,int cy,int uFlags); //将窗口设置在最前
public static void SetWindowPos(IntPtr hWnd)
{
SetWindowPos(hWnd, -1, 0, 0, 0, 0, 3);
}
//IntPtr iptr = new IntPtr(FindWindow(null, "YY5.3"));
private void btnSend_Click(object sender, EventArgs e)
{
IntPtr iptr = new IntPtr(FindWindow(null, "YY5.3"));
if (iptr==IntPtr.Zero)
{
MessageBox.Show("没找到");
return;
}
else
{
SetWindowPos(iptr);
SendKeys.Send("qq970262810");
SendKeys.Send("{tab}");
SendKeys.Send("A106116a");
SendKeys.Send("enter");
}
}
}
}sendkeys
建议每个Send后面加个延时,有时候程序很快电脑反应不过来
还是没用啊,我把以上内容发送给QQ,QQ可以正确的识别回车键,但是登录提示密码不正确啊