Nukepayload2 / Nukepayload2.Diagnostics.InputInjection

A .NET Standard Port of Windows.UI.Input.Preview.Injection
GNU Lesser General Public License v3.0
2 stars 0 forks source link

Nukepayload2.Diagnostics.InputInjection

A .NET Standard Port of Windows.UI.Input.Preview.Injection

Download on Nuget

You can use it for software testing or writing tools for cheating in games.

We provide wrapped undocumented APIs in the Nukepayload2.Diagnostics.Preview namespace.

Commonly used types:

Requirements

Sample

Touch at 123, 456 for 789 milliseconds with SendTouch

VB

SendTouch(123, 456, 789)

C#

SendTouch(123, 456, 789);

Touch at 123, 456 for 789 milliseconds with InputInjection

VB

Dim injection = InputInjector.TryCreate
If injection Is Nothing Then MsgBox("Your system is too old to use touch injection.", vbExclamation, "Not supported")
injection.InitializeTouchInjection(InjectedInputVisualizationMode.Default)
Const PosX = 123
Const PosY = 456
Const DurationMilliseconds = 789

With injection
    Dim touch As New InjectedInputTouchInfo With {
        .PointerInfo = New InjectedInputPointerInfo With {
            .PointerId = CUInt(pointerId),
            .PixelLocation = New InjectedInputPoint With {
                .PositionX = PosX, ' Y co-ordinate of touch on screen
                .PositionY = PosY ' X co-ordinate of touch on screen
            },
            .PointerType = PointerInputType.Touch ' Must be set to PointerInputType.Touch. It's different from UWP.
        },
        .TouchParameters =
            InjectedInputTouchParameters.Contact Or
            InjectedInputTouchParameters.Orientation Or
            InjectedInputTouchParameters.Pressure, ' TouchMask
        .Orientation = 90,
        .Pressure = 1024
    }
    ' defining contact area (I have taken area of 30 x 30 pixel)
    Dim pxLoc As InjectedInputPoint = touch.PointerInfo.PixelLocation
    touch.Contact = New InjectedInputRectangle With {
        .Top = pxLoc.PositionY - 15,
        .Bottom = pxLoc.PositionY + 15,
        .Left = pxLoc.PositionX - 15,
        .Right = pxLoc.PositionX + 15
    }

    ' TouchDown
    touch.PointerInfo.PointerOptions =
        InjectedInputPointerOptions.PointerDown Or
        InjectedInputPointerOptions.InRange Or
        InjectedInputPointerOptions.InContact

    .InjectTouchInput(touch) ' Injecting the touch Down from screen

    ' Hold
    touch.PointerInfo.PointerOptions =
        InjectedInputPointerOptions.Update Or
        InjectedInputPointerOptions.InRange Or
        InjectedInputPointerOptions.InContact

    Dim timer As New Stopwatch
    timer.Start()
    Do While timer.ElapsedMilliseconds < DurationMilliseconds
        .InjectTouchInput(touch)
    Loop
    timer.Stop()
    ' TouchUp
    touch.PointerInfo.PointerOptions = InjectedInputPointerOptions.PointerUp
    .InjectTouchInput(touch) ' Injecting the touch Up from screen
End With

Progress