//点击button按钮获取 文本框,title------------需要测试获取文本信息 static void GetControlTest() { var bar = WinApi.FindWindow(null, "发票号码确认"); var child = WinApi.FindWindowEx(bar, IntPtr.Zero, null, "确认"); //WinApi.LeftClick(child); //WinApi.SendMessage(child, 0x00F5, IntPtr.Zero, "");//按钮点击事件--亲测可行 WinApi.PostMessage(child, 0x00F5, 5, 5);//按钮点击事件 }
public static bool LeftClick(IntPtr hWnd) { var btDownResult = WinApi.PostMessage(hWnd, 0x0201, 0, 0); Thread.Sleep(10); var btUpResult = WinApi.PostMessage(hWnd, 0x0202, 0, 0); return(btDownResult && btUpResult); }
public static void leftClick(IntPtr hWnd1) { IntPtr hWnd = (IntPtr)hWnd1; if (hWnd != IntPtr.Zero) { WinApi.PostMessage(hWnd, 0x0201, 0, 0); WinApi.PostMessage(hWnd, 0x0202, 0, 0); } }
/// <summary> /// 向直定句柄的窗体发送键盘键值 /// 所对应的的键盘值: https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes /// </summary> internal static void SendKey(IntPtr intPtr, int key) { //这种方式发送的是双字符 WinApi.PostMessage(intPtr, KeySnap.WM_KEYDOWN, key, 0); //WinApi.PostMessage(intPtr, KeySnap.WM_KEYUP, key, 0); //这种方式发送的是单字符 //WinApi.PostMessage(intPtr, KeySnap.WM_SYSKEYDOWN, key, 0); //WinApi.PostMessage(intPtr, KeySnap.WM_SYSKEYUP, key, 0); }
/// <summary> /// 卷票折扣功能 /// </summary> static void JuanPiaoZheKou() { Thread.Sleep(3000); var bar = WinApi.FindWindow(null, "开具增值税普通发票(卷票)"); var child = WinApi.FindWindowEx(bar, IntPtr.Zero, null, "FPtiankai_new"); var child1 = WinApi.FindWindowEx(child, IntPtr.Zero, null, null); var child2 = WinApi.FindWindowEx(child, child1, null, null); RECT rect; HandleRef ptrT = new HandleRef(null, child2); WinApi.GetWindowRect(ptrT, out rect); WinApi.ClickLocation(child2, rect.right - rect.left - 290, 25); //点击折扣 Thread.Sleep(500); var bar1 = WinApi.FindWindow(null, "添加折扣行"); var list = WinApi.EnumChilWindowsIntptr(bar1).Select(i => (int)i).ToList(); if (list == null || list.Count < 7) { return; } WinApi.SendMessage((IntPtr)list[6], 0x0C, IntPtr.Zero, "2.5"); //Thread.Sleep(1000); //WinApi.keybd_event(Keys.Tab, 0, 0, 0); //Thread.Sleep(1000); //WinApi.keybd_event(Keys.Tab, 0, 0, 0); //Thread.Sleep(1000); //WinApi.keybd_event(Keys.Tab, 0, 0, 0); //Thread.Sleep(1000); //WinApi.keybd_event(Keys.Enter, 0, 0, 0); Thread.Sleep(1000); WinApi.PostMessage((IntPtr)list[4], 0x00F5, 0, 0); //WinApi.LeftClick((IntPtr)list[4]); //WinApi.SendKey((IntPtr)list[4], KeySnap.VK_ENTER); //WinApi.ClickLocation((IntPtr) list[4],1,1); Console.ReadKey(); }
/// <summary> /// 左键点击放遮挡 /// </summary> /// <param name="intPtr"></param> public static void LeftClickMsg(IntPtr intPtr) { WinApi.PostMessage(intPtr, 245, 0, 0); Thread.Sleep(10); }