【问题标题】:How to tap two points with InjectTouchInput如何使用 InjectTouchInput 点击两个点
【发布时间】:2020-06-02 05:19:45
【问题描述】:

我想用InjectTouchInput()点击两个点(c[0]c[1]),但只有c[1]被点击,c[0]没有被点击。

有什么问题吗?

InjectTouchInput() 是一个模拟触摸事件的 API。

https://docs.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-injecttouchinput

它可以被C#调用。 https://www.nuget.org/packages/TCD.System.TouchInjection/

using System;
using TCD.System.TouchInjection;
using static TCD.System.TouchInjection.TouchInjector;


// https://docs.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-injecttouchinput?redirectedfrom=MSDN

namespace HelloWorld
{
    class Program
    {
        private static PointerTouchInfo createPointer(uint id)
        {
            var pointer = new PointerTouchInfo();
            //We can add different additional touch data 
            pointer.TouchMasks = TouchMask.PRESSURE;
            pointer.Pressure = 100;


            //Pointer ID is for gesture tracking 
            pointer.PointerInfo.PointerId = id;
            pointer.PointerInfo.pointerType = PointerInputType.TOUCH;

            return pointer;
        }
        private static void tap(int x, int y)
        {
            var c = new[] { createPointer(1), createPointer(2) };

            // Touch contact down
            c[0].PointerInfo.PtPixelLocation.X = x;
            c[0].PointerInfo.PtPixelLocation.Y = y;
            c[0].PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.DOWN;
            c[1].PointerInfo.PtPixelLocation.X = x+110;
            c[1].PointerInfo.PtPixelLocation.Y = y;
            c[1].PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.DOWN;
            InjectTouchInput(2, c);

            // Touch contact up and transition to hover
            c[0].PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.UP;
            c[1].PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.UP;
            InjectTouchInput(2, c);

        }
        static void Main(string[] args)
        {
            if (InitializeTouchInjection())
            {
                tap(350, 650);
            } else
            {
                Console.WriteLine("Error");
            }

            Console.WriteLine("Hello Tap Emulation!");
        }
    }
}

【问题讨论】:

  • 双指触摸输入通常会被翻译成与右键单击相对应的内容。这会干扰吗?
  • 两个触摸事件不会转化为右键单击。在 c[0] 点和 c[1] 点上显示了两个触摸效果。 (但只点击了 c[1])。或许,touch-down emulate 是可以的,但 touch-up emulate 是错误的。

标签: c# windows winapi touch touch-event


【解决方案1】:

浏览器触控测试

Multitouch Test

Touch events - Example - code sample

Touch events - Web API | MDN

color for touch with identifier 1 = #100
touchend
color for touch with identifier 0 = #000
touchend
touchstart:0.
color for touch with identifier 1 = #100
touchstart:0...
touchstart.
touchstart:0.
color for touch with identifier 0 = #000
touchstart:0...
touchstart.
initialized.

浏览器测试工作正常。 这可能不是代码问题,而是应用程序...

【讨论】:

  • 你可以accept你自己的答案。
猜你喜欢
  • 1970-01-01
  • 2021-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-07
  • 1970-01-01
  • 1970-01-01
  • 2016-07-17
相关资源
最近更新 更多