C#句柄的操作(鼠标移动、键盘点击、复制粘贴)
创始人
2024-02-16 04:38:13
0
--模拟键盘点击--
[DllImport("user32.dll",EntryPoint = "keybd_event",SetLastError = true)]
public static extern void keybd_event(Keys bVk,byte bScan,uint dwFlags,uint dwExtraInfo);
public static void CtrlAAndCtrlC()
{Keybd_event(Keys.ControlKey,0,0,0);keybd_event(Keys.A,0,0,0);keybd_event(Keys.C,0,0,0);keybd_event(Keys.ControlKey,0,KEYEVENTF_KEYUP);
}--鼠标移动到固定位置--
[DllImport("user32.dll")]
public static extern int SetCursorPos(int x, int y);--鼠标点击--
[DllImport("user32.dll",EntryPoint = "PostMessage",CallingConvention = CallingConvention.Winapi)]
public static extern int PostMessage(IntPtr hwnd, int msg, uint wParam, uint IParm);--最大最小关闭窗口--
[DllImport("user32.dll",CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);--将窗口显示到最前端--
[DllImport("user32.dll",EntryPoint = "EnumChildWindows")]
public static extern int EnumChildWindows(IntPtr hwndParent, CallBack callBack, int IParm);
public delegate bool CallBack(IntPtr hwnd, int IParam);--获取窗体文本--
[DllImport("user32.dll",EntryPoint = "GetWindowText")]
public static extern int GetWindowText(IntPtr hwnd, StringBuilder text, int maxLength);--获取窗体Class文本--
[DllImport("user32.dll",EntryPoint = "GetClassText")]
public static extern int GetClassText(IntPtr hwnd, StringBuilder text, int maxLength);----
[DllImport("user32.dll",EntryPoint = "GetWindowLong")]
public static extern int GetWindowLong(IntPtr hwnd, int nIndex);--设置文本--
[DllImport("user32.dll",EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hwnd, int msg, int wParam, StringBuilder IParam);--设置文本--
[DllImport("user32.dll",EntryPoint = "SetWindowText")]
public static extern int SetWindowText(IntPtr hwnd, string text);--设置键盘点击--
[DllImport("user32.dll",EntryPoint = "PostMessageA", SetLastError = true)]
public static extern int PostMessageA(IntPtr hwnd, int msg, Keys wParm, uint IParm);--导出进程--
[DllImport("user32.dll",EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);--让窗口置于所有页面最前端--
[DllImport("user32.dll",CharSet.Auto)]
public static extern bool SwitchToThisWindow(IntPtr hwnd, bool fAltTab);--鼠标运动到位置并点击--
[DllImport("user32.dll")]
public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);--模拟鼠标点击抬起--
public static void MouserDownAndUp(IntPtr hwnd, ushort x, ushort y)
{PostMessage(hwnd, WM_Lbutton, 0 (((uint)x) << 16 | y)));PostMessage(hwnd, WM_LBUTTONUP, 0 (((uint)x) << 16 | y)));
}public const int WM_Lbutton = 0x0201;//鼠标左键按下
public const int WM_LBUTTONUP = 0x0202;//鼠标左键抬起
public const int WM_SETTEXT = 0x000C;//设置文本--获取所有进程列表--
public static List GetChildWindows(IntPtr hwnd)
{var list = new List();StringBuilder sb = new StringBuilder(4048);car idx = 0;EnumChildWindows(hwnd, (IntPtr childHwnd, int IParam) => {WindowInfo wi = new WindowInfo(){Hwnd = childHwnd,Idx = idx++,	};GetWindowText(childHwnd, sb, sb.Capacity);wi.WindowName = sb.ToString();GetClassName(childHwnd, sb, sb.Capacity);wi.ClassName = sb.ToString();wi.GWL_EXSTYLE = GetWindowLong(childHwnd,GWL_EXSTYLE).ToString();wi.GWL_HINSTANCE = GetWindowLong(childHwnd,GWL_HINSTANCE).ToString();wi.GWL_ID = GetWindowLong(childHwnd,GWL_ID).ToString();wi.GWL_STYLE = GetWindowLong(childHwnd,GWL_STYLE).ToString();list.Add(wi);return true;},0);return list;
}public class WindowInfo
{public WindowInfo(){}public int Idx { get;set; };public IntPtr Hwnd { get;set; };public string WindowName { get;set; };public string ClassName { get;set; };public string GWL_EXSTYLE { get;set; };public string GWL_HINSTANCE { get;set; };public string GWL_ID { get;set; };public string GWL_STYLE h{ get;set; };
}

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
苏州离哪个飞机场近(苏州离哪个... 本篇文章极速百科小编给大家谈谈苏州离哪个飞机场近,以及苏州离哪个飞机场近点对应的知识点,希望对各位有...
客厅放八骏马摆件可以吗(家里摆... 今天给各位分享客厅放八骏马摆件可以吗的知识,其中也会对家里摆八骏马摆件好吗进行解释,如果能碰巧解决你...