Skip to content

Instantly share code, notes, and snippets.

@flowerinthenight
Last active August 5, 2017 03:35
Show Gist options
  • Save flowerinthenight/bd264001034db093413a0bb233760588 to your computer and use it in GitHub Desktop.
Save flowerinthenight/bd264001034db093413a0bb233760588 to your computer and use it in GitHub Desktop.
#include <Windows.h>
BOOL TouchInput(POINTER_FLAGS pointerFlags, int x, int y)
{
POINTER_TOUCH_INFO contact = { 0 };
contact.pointerInfo.pointerType = PT_TOUCH;
contact.pointerInfo.pointerFlags = pointerFlags;
contact.pointerInfo.ptPixelLocation.x = x;
contact.pointerInfo.ptPixelLocation.y = y;
contact.pointerInfo.pointerId = 0;
return InjectTouchInput(1, &contact);
}
BOOL TouchInputDown(int x, int y)
{
return TouchInput(POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_DOWN, x, y);
}
BOOL TouchInputDrag(int x, int y)
{
return TouchInput(POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT | POINTER_FLAG_UPDATE, x, y);
}
BOOL TouchInputUp(int x, int y)
{
return TouchInput(POINTER_FLAG_INRANGE | POINTER_FLAG_UP, x, y);
}
// Left to right swipe simulation (app switch in Win8/8.1)
void SimulateTouchSwipe()
{
InitializeTouchInjection(1, TOUCH_FEEDBACK_NONE);
int x = 0, y = 10;
TouchInputDown(0, 10);
for (int itr = 0; itr < 100; ++itr) {
x = (itr * 10);
TouchInputDrag(x, y);
}
TouchInputUp(x, y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment