C# API初学 制定坐标实现11对战平台自动登录

Posted on 2015-09-26 20:27  虹狐  阅读(361)  评论(0)    收藏  举报
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace apitest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [DllImport("user32.dll", EntryPoint = "SetCursorPos")]
        private static extern int SetCursorPos(int x, int y);

        [DllImport("user32.dll", EntryPoint = "mouse_event")]
        public static extern void mouse_event(
            int dwFlags,
            int dx,
            int dy,
            int cButtons,
            int dwExtraInfo
        );

        const int MOUSEEVENTF_MOVE = 0x0001;     // 移动鼠标           (十):1
        const int MOUSEEVENTF_LEFTDOWN = 0x0002; //模仿鼠标左键按下    (十):2
        const int MOUSEEVENTF_LEFTUP = 0x0004; //模仿鼠标左键抬起    (十):4
        const int MOUSEEVENTF_RIGHTDOWN = 0x0008; //模仿鼠标右键按下    (十):8
        const int MOUSEEVENTF_RIGHTUP = 0x0010; //模仿鼠标右键抬起    (十):16
        const int MOUSEEVENTF_MIDDLEDOWN = 0x0020;// 模仿鼠标中键按下    (十):32
        const int MOUSEEVENTF_MIDDLEUP = 0x0040;// 模仿鼠标中键抬起    (十):64
        const int MOUSEEVENTF_ABSOLUTE = 0x8000; //标示是否采取绝对坐标    (十):32768

        private void Form1_Load(object sender, EventArgs e)
        {
            int iX = 710;
            int iY = 510;
            SendKeys.SendWait("HongHu123");
            SetCursorPos(iX, iY);
            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
            System.Threading.Thread.Sleep(500);//设置暂停时间,不然账号和密码会发在一个框中

            SendKeys.SendWait("{Tab}");//发送Tab
            SendKeys.SendWait("PWD123456"); //输入游戏密码
            SendKeys.SendWait("{ENTER}");//输入回车键
        }
    }
}
View Code