简体   繁体   English

在Windows 10上注册触摸事件(无需单击鼠标或实际触摸)

[英]Register a touch event on Windows 10 (without a mouse click or actual touch)

I'm developing an application for windows 10 (PC device) that uses the capability of "tablet mode". 我正在为Windows 10(PC设备)开发一个使用“平板电脑模式”功能的应用程序。

I want to register a touch event on a given x and y position (without a mouse click or actual touch). 我想在给定的x和y位置上注册触摸事件(无需单击鼠标或实际触摸)。 What are the APIs for handling this kind of action in C#? 在C#中用于处理此类操作的API有哪些?

If you want to simulate touch event in Windows there is a Win32 API for it. 如果要在Windows中模拟触摸事件,则可以使用Win32 API。

MSDN: InjectTouchInput MSDN:InjectTouchInput

NuGet: C# wrapper NuGet:C#包装器

You can simulate absolutely any combination of pointer input that Windows 10 is capable of, including pressure, contact area, pens, touch, mouse, multitouch, etc. 您可以模拟Windows 10能够完全实现的指针输入的任何组合,包括压力,接触面积,笔,触摸,鼠标,多点触摸等。

Sample code: 样例代码:

//usings:
using TCD.System.TouchInjection;
using static TCD.System.TouchInjection.TouchInjector;


// code:

InitializeTouchInjection();

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 = 1;
pointer.PointerInfo.pointerType = PointerInputType.TOUCH;

pointer.PointerInfo.PtPixelLocation.X = 200;
pointer.PointerInfo.PtPixelLocation.Y = 200;

pointer.PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.INCONTACT | PointerFlags.DOWN;

InjectTouchInput(1, new[] { pointer });

//Hold touch for some time
Thread.Sleep(100);

pointer.PointerInfo.PointerFlags = PointerFlags.UPDATE;

InjectTouchInput(1, new []{ pointer });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM