如何使用 InjectTouchInput 点击两个点
How to tap two points with InjectTouchInput
我想用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!");
}
}
}
浏览器触摸测试
Touch events - Example - code sample
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.
浏览器测试正常。
这可能不是代码问题,而是应用程序...
我想用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!");
}
}
}
浏览器触摸测试
Touch events - Example - code sample
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.
浏览器测试正常。 这可能不是代码问题,而是应用程序...