using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;

namespace ryCommon.SysFuns
{
    /// <summary>
    /// 对鼠标或键盘的自动化操作
    /// </summary>
   public class Auto
    {
        uint WM_LBUTTONDOWN = 0x201;
        uint WM_LBUTTONUP = 0x202;

        [DllImport("user32.dll", SetLastError = true)]
        static extern bool SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
        private int MakeLParam(int LoWord, int HiWord)
        {
            return ((HiWord << 16) | (LoWord & 0xffff));
        }
        /// <summary>
        ///左键单击鼠标(支持后台单击)
        /// </summary>
        /// <param name="handle">指定要发送单击命令的句柄</param>
        /// <param name="x">坐标x(句柄内的坐标,非屏幕坐标)</param>
        /// <param name="y">坐标y(句柄内的坐标,非屏幕坐标)</param>
        public void LeftClick(IntPtr handle, int x, int y)
        {
            SendMessage(handle, WM_LBUTTONDOWN, 1, MakeLParam(x, y));
            SendMessage(handle, WM_LBUTTONUP, 0, MakeLParam(x, y));
        }
    }
}
