日期:2020-06-24  浏览次数:3305 次

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        [DllImport("User32.dll")]
        public static extern bool SetWindowText(IntPtr hwnd, string title);

        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
        //Mouse actions
        private const int MOUSEEVENTF_LEFTDOWN = 0x02;
        private const int MOUSEEVENTF_LEFTUP = 0x04;
        private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
        private const int MOUSEEVENTF_RIGHTUP = 0x10;

        static void Main(string[] args)
        {
            while (true)
            {
                Thread.Sleep(100);
                CheckProcess();
            }
        }

        private static void CheckProcess()
        {
            Process[] processlist = Process.GetProcessesByName("chrome");//获取谷歌浏览器

            foreach (Process process in processlist)
            {
                String windowTitle = process.MainWindowTitle;
                if (windowTitle.Contains("watch_chrome_position"))
                {
                    String[] Titles = Regex.Split(windowTitle, "watch_chrome_position");
                    String windowTitleStart = Titles[0];
                    String position_str = Regex.Match(Titles[1], "[\\w]*").ToString();
                    String[] positions = Regex.Split(position_str, "_");
                    uint X = Convert.ToUInt32(positions[0]);
                    uint Y = Convert.ToUInt32(positions[1]);
                    //DoMouseClick(200, 200);//双击窗口
                    SetWindowText(process.MainWindowHandle, "333333");
                    Console.WriteLine(windowTitle);
                }
            }
        }

        private static void DoMouseClick(uint X, uint Y)
        {
            //Call the imported function with the cursor's current position
            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
        }
    }
}