When using the InjectTouchInput function, the touchpad(via I2C) is not working

Dean Tang 20 Reputation points
2023-07-17T04:02:01.5633333+00:00

Hi,

I'm attempting to use the InjectTouchInput function to simulate touchscreen behavior with the touchpad. However, currently when calling InjectTouchInput to simulate cursor movement, there is no response when sliding or clicking on the touchpad (via I2C).

Code to do simulating movement:

                        if (bool_down) {
                            var p2 = getPos();
                            int nMoveIntervalX = (int)((p2.X - pp.X));
                            int nMoveIntervalY = (int)((p2.Y - pp.Y));

                            //Simulating touch - movement.
                            contact.Move(nMoveIntervalX, nMoveIntervalY);
                            oFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                            contact.PointerInfo.PointerFlags = oFlags;
                            TouchInjector.InjectTouchInput(1, new[] { contact });
        public void Move(int deltaX, int deltaY) {
            PointerInfo.PtPixelLocation.X += deltaX;
            PointerInfo.PtPixelLocation.Y += deltaY;
            ContactArea.left += deltaX;
            ContactArea.right += deltaX;
            ContactArea.top += deltaY;
            ContactArea.bottom += deltaY;
        }
        [DllImport("User32.dll")]
        public static extern bool InjectTouchInput(int count, [MarshalAs(UnmanagedType.LPArray), In] PointerTouchInfo[] contacts);

Here is a sample code for reference:
Here is a sample code for reference:
https://github.com/hbl917070/Mouse2Touch

Currently, the following types of mouse/touchpad are ok: external USB cable mouse, wireless mouse, and the touchpad via PS2.

Is there any solution to fix it?

Thanks.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,352 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,949 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 10,706 Reputation points Microsoft Vendor
    2023-07-18T05:10:58.28+00:00

    Hello @Dean Tang,

    It's worth noting that the injected input is sent to the desktop of the session where the injection process is running. We're not in a position to know whether InjectTouchInput blocks the I2C channel or not but there is another driver sample HIDInjector you can check.

    As this issue is complex, please open an incident at link below so that our engineer can work with you closely: https://developer.microsoft.com/en-us/windows/support/?tabs=Contact-us and please choose the 'Desktop app UI development - Windows controls and common dialogs' for Windows SDK for this issue. In-addition, if the support engineer determines that the issue is the result of a bug the service request will be a no-charge case and you won't be charged.

    0 comments No comments

0 additional answers

Sort by: Most helpful