internal unsafe Pointer(IntPtr ptr, int dataSize = 0, PointerFlags flags = PointerFlags.None) : this() { DataSize = dataSize; _ptr = (byte *)ptr; Flags = flags; }
/// <summary> /// Helper method to create the most used <see cref="POINTER_TOUCH_INFO"/> structure. /// </summary> /// <param name="point">The point where the touch action occurs.</param> /// <param name="flags">The flags used for the touch action</param> /// <param name="id">The id of the point, only needed when more than one.</param> /// <returns>A <see cref="POINTER_TOUCH_INFO"/> structure.</returns> private static POINTER_TOUCH_INFO CreatePointerTouch(Point point, PointerFlags flags, uint id = 0) { var touchPoint = point.ToPOINT(); var contact = new POINTER_TOUCH_INFO { pointerInfo = { pointerType = PointerInputType.PT_TOUCH, pointerFlags = flags, ptPixelLocation = touchPoint, pointerId = id, }, touchFlags = TouchFlags.NONE, touchMask = TouchMask.NONE, rcContact = new RECT { left = touchPoint.X, right = touchPoint.X, top = touchPoint.Y, bottom = touchPoint.Y } }; return(contact); }
internal unsafe Pointer(byte *ptr, Action unprotectIt = null, int dataSize = 0, PointerFlags flags = PointerFlags.None) : this() { DataSize = dataSize; _ptr = ptr; Flags = flags; _unprotectIt = unprotectIt; }
internal unsafe Pointer(IntPtr ptr, Action unprotectIt = null, int dataSize = 0, PointerFlags flags = PointerFlags.None) : this() { DataSize = dataSize; // Console.WriteLine($"ptr: 0x{(ulong) ptr:X} 0x{((ulong) (byte*) ptr):X}"); _ptr = (byte *)ptr; Flags = flags; _unprotectIt = unprotectIt; }
private PointerTouchInfo MakePointerTouchInfo(PointerInputType pointer, PointerFlags click, int x, int y, int radius, uint id, string type, uint orientation = 90, uint pressure = 32000) { var contact = new PointerTouchInfo { PointerInfo = { pointerType = pointer }, TouchFlags = TouchFlags.NONE, Orientation = orientation, Pressure = pressure }; if (type == "Start") { contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; } else if (type == "Move") { contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; } else if (type == "End") { contact.PointerInfo.PointerFlags = PointerFlags.UP; } else if (type == "EndToHover") { contact.PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE; } else if (type == "Hover") { contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE; } else if (type == "EndFromHover") { contact.PointerInfo.PointerFlags = PointerFlags.UPDATE; } contact.PointerInfo.PointerFlags |= click; contact.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE; contact.PointerInfo.PtPixelLocation.X = x; contact.PointerInfo.PtPixelLocation.Y = y; contact.PointerInfo.PointerId = id; contact.ContactArea.left = x - radius; contact.ContactArea.right = x + radius; contact.ContactArea.top = y - radius; contact.ContactArea.bottom = y + radius; return(contact); }
private void ConvertToNewTouchInfo(PointerTouchInfo[] contacts, PointerFlags flags) { for (var i = 0; i < contacts.Length; i++) { var oldPointerInfo = contacts[i].PointerInfo; contacts[i].PointerInfo = new PointerInfo() { pointerType = PointerInputType.TOUCH, PointerFlags = flags, PointerId = (uint)i + 1,// oldPointerInfo.PointerId, PtPixelLocation = oldPointerInfo.PtPixelLocation }; contacts[i].TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE; contacts[i].ContactAreaRaw = new ContactArea(); } }
private void SimulateTouch(int x, int y) { // Touch Down Simulate PointerTouchInfo contact = MakePointerTouchInfo(x, y, 5, 1); PointerFlags oFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; contact.PointerInfo.PointerFlags = oFlags; bool bIsSuccess = TouchInjector.InjectTouchInput(1, new[] { contact }); // Touch Move Simulate int nMoveIntervalX = this.GetRandomSeed().Next(-60, 60); int nMoveIntervalY = this.GetRandomSeed().Next(-60, 60); contact.Move(nMoveIntervalX, nMoveIntervalY); oFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.UPDATE; contact.PointerInfo.PointerFlags = oFlags; TouchInjector.InjectTouchInput(1, new[] { contact }); // Touch Up Simulate contact.PointerInfo.PointerFlags = PointerFlags.UP; TouchInjector.InjectTouchInput(1, new[] { contact }); }
private Pointer.PointerButtonState updateButtons(Pointer.PointerButtonState current, PointerFlags flags, ButtonChangeType change) { var currentUpDown = ((uint)current) & 0xFFFFFC00; var pressed = ((uint)flags >> 4) & 0x1F; var newUpDown = 0U; if (change != ButtonChangeType.None) { newUpDown = 1U << (10 + (int)change); } var combined = (Pointer.PointerButtonState)(pressed | newUpDown | currentUpDown); return(combined); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender2, EventArgs e2) { String html_path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "main_ui.html"); if (File.Exists(html_path)) { webBrowser1.Navigate(html_path); webBrowser1.ObjectForScripting = new C_js_to_net(this); //讓網頁允許存取C# webBrowser1.AllowNavigation = false; //禁止載入其他網頁 //webBrowser1.IsWebBrowserContextMenuEnabled = false;//禁止右鍵 } else { webBrowser1.DocumentText = $"Can't find 「{html_path}」"; } TouchInjector.InitializeTouchInjection();//初始化觸控API // var tim = new System.Windows.Forms.Timer(); tim.Interval = 200; tim.Tick += (sender, e) => { String gn = GetWindowsName.GetName();//取得目前焦點視窗的名稱 //與「排除名單」進行比對 foreach (var item in ar_ad) { if (gn.IndexOf(item, StringComparison.CurrentCultureIgnoreCase) > -1) { bool_stop = true; return; } } bool_stop = false; }; tim.Start(); new Thread(() => { while (bool_exe_run) { if (mtype == Mtype.滑鼠右鍵_2) { bool bool_d = bool_down_mr; // Touch Down Simulate if ((bool_down == false) && bool_d) { bool_down = true; pp = getPos(); pp_start = pp; bool_down_mr_moved = false; } // Touch Up Simulate if (bool_down && (bool_d == false)) { bool_down = false; if (bool_down_mr_moved) { //模擬觸控-結束 contact.PointerInfo.PointerFlags = PointerFlags.UP; TouchInjector.InjectTouchInput(1, new[] { contact }); } else { RightClick(); } bool_down_mr_moved = false; //upFull(); } else // Touch Move Simulate if (bool_down) { var p2 = getPos(); if (bool_down_mr_moved) { //模擬觸控-移動 int nMoveIntervalX = (int)((p2.X - pp.X) * f_touch_speed); int nMoveIntervalY = (int)((p2.Y - pp.Y) * f_touch_speed); contact.Move(nMoveIntervalX, nMoveIntervalY); oFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.UPDATE; contact.PointerInfo.PointerFlags = oFlags; TouchInjector.InjectTouchInput(1, new[] { contact }); //讓滑鼠跟隨觸控的位置 if (f_touch_speed != 1) { NativeMethods.SetCursorPos(pp.X + nMoveIntervalX, pp.Y + nMoveIntervalY); p2 = getPos(); } pp = p2; if (overd_sc(pp)) //超出螢幕時自動停止觸控 { upFull(); } } else { if (func_位移(pp_start, p2)) { bool_down_mr_moved = true; //模擬觸控-開始 contact = MakePointerTouchInfo(pp_start.X, pp_start.Y); oFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; contact.PointerInfo.PointerFlags = oFlags; bool bIsSuccess = TouchInjector.InjectTouchInput(1, new[] { contact }); } } } } else { bool bool_d = bool_down_b1 || bool_down_ml || bool_down_mr || bool_down_mm; // Touch Down Simulate if ((bool_down == false) && bool_d) { bool_down = true; pp = getPos(); if (mtype == Mtype.滑鼠右鍵) { bool_m_handled = false; } //模擬觸控-開始 contact = MakePointerTouchInfo(pp.X, pp.Y); oFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; contact.PointerInfo.PointerFlags = oFlags; bool bIsSuccess = TouchInjector.InjectTouchInput(1, new[] { contact }); if (mtype == Mtype.滑鼠右鍵) { Thread.Sleep(1); bool_m_handled = true; } } // Touch Up Simulate if (bool_down && (bool_d == false)) { bool_down = false; if (mtype == Mtype.滑鼠右鍵) { bool_m_handled = false; } //模擬觸控-結束 contact.PointerInfo.PointerFlags = PointerFlags.UP; TouchInjector.InjectTouchInput(1, new[] { contact }); if (mtype == Mtype.滑鼠右鍵) { Thread.Sleep(1); bool_m_handled = true; } } // Touch Move Simulate if (bool_down) { var p2 = getPos(); int nMoveIntervalX = (int)((p2.X - pp.X) * f_touch_speed); int nMoveIntervalY = (int)((p2.Y - pp.Y) * f_touch_speed); //模擬觸控-移動 contact.Move(nMoveIntervalX, nMoveIntervalY); oFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.UPDATE; contact.PointerInfo.PointerFlags = oFlags; TouchInjector.InjectTouchInput(1, new[] { contact }); //讓滑鼠跟隨觸控的位置 if (f_touch_speed != 1) { NativeMethods.SetCursorPos(pp.X + nMoveIntervalX, pp.Y + nMoveIntervalY); p2 = getPos(); } pp = p2; if (overd_sc(pp)) //超出螢幕時自動停止觸控 { upFull(); } } } Thread.Sleep(11); } }).Start(); HookManager.MouseDown += HookManager_MouseDown; HookManager.MouseUp += HookManager_MouseUp; //HookManager.MouseMove += HookManager_MouseMove; this.FormClosing += Form1_FormClosing; init_nIcon(); }