gpt4 book ai didi

visual-c++ - 为什么在 WIN8 下使用 Touch Injection API 时只能注入(inject)一次触摸?

转载 作者:行者123 更新时间:2023-12-01 20:07:54 25 4
gpt4 key购买 nike

我正在尝试测试触摸注入(inject) API,以便在使用 Windows 8 时注入(inject)多个触摸。为此,我创建 5 个联系人,然后模拟悬停,然后拖动并释放。

这对于一键接触来说效果很好。然而,当我再添加 4 个联系人时,没有任何变化,即它产生的结果与只有一个联系人相同。 (我通过在屏幕右侧打开 Paint 并在左侧打开 Visual Studio 进行测试。然后,当程序运行时,在绘画窗口中对角绘制一条线)。当我在 InitializeTouchInjection 之后运行 GetLastError() 时,它给出了 5,这是一个无效的访问错误。

有我应该使用的标志吗?我的电脑需要安装特定的驱动程序吗?这里出了什么问题?

这是代码:

#include <windows.h>

void Drag(int x, int y){
POINTER_TOUCH_INFO contact_[5];
BOOL bRet = TRUE;

InitializeTouchInjection(5, TOUCH_FEEDBACK_DEFAULT);

for (int c=0;c<5;c++)
{
POINTER_TOUCH_INFO &contact=contact_[c];
memset(&contact, 0, sizeof(POINTER_TOUCH_INFO));
contact.pointerInfo.pointerType = PT_TOUCH;
contact.pointerInfo.pointerId = c; //contact 0
contact.pointerInfo.ptPixelLocation.y = y; // Y co-ordinate of touch on screen
contact.pointerInfo.ptPixelLocation.x = x+50*c; // X co-ordinate of touch on screen

contact.touchFlags = TOUCH_FLAG_NONE;
contact.touchMask = TOUCH_MASK_CONTACTAREA | TOUCH_MASK_ORIENTATION | TOUCH_MASK_PRESSURE;
contact.orientation = 90; // Orientation of 90 means touching perpendicular to screen.
contact.pressure = 32000;

// defining contact area (I have taken area of 4 x 4 pixel)
contact.rcContact.top = contact.pointerInfo.ptPixelLocation.y - 2;
contact.rcContact.bottom = contact.pointerInfo.ptPixelLocation.y + 2;
contact.rcContact.left = contact.pointerInfo.ptPixelLocation.x - 2;
contact.rcContact.right = contact.pointerInfo.ptPixelLocation.x + 2;

//contact.pointerInfo.pointerFlags = POINTER_FLAG_DOWN | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
contact.pointerInfo.pointerFlags = POINTER_FLAG_UPDATE | POINTER_FLAG_INRANGE ;//| POINTER_FLAG_INCONTACT;
}
InjectTouchInput(5, contact_); // Injecting the touch down on screen
Sleep(20);

for(int i=0;i<200;i++)
{
for (int c=0;c<5;c++)
{
POINTER_TOUCH_INFO &contact=contact_[c];
contact.pointerInfo.ptPixelLocation.x--; // updating the X Co-ordinate to x-100 pixels
contact.pointerInfo.ptPixelLocation.y++;

contact.rcContact.top = contact.pointerInfo.ptPixelLocation.y - 2;
contact.rcContact.bottom = contact.pointerInfo.ptPixelLocation.y + 2;
contact.rcContact.left = contact.pointerInfo.ptPixelLocation.x - 2;
contact.rcContact.right = contact.pointerInfo.ptPixelLocation.x + 2;
if (i==100)
contact.pointerInfo.pointerFlags = POINTER_FLAG_INCONTACT | POINTER_FLAG_INRANGE | POINTER_FLAG_DOWN;
if (i>100)
contact.pointerInfo.pointerFlags = POINTER_FLAG_INCONTACT | POINTER_FLAG_INRANGE | POINTER_FLAG_UPDATE;
}
InjectTouchInput(5, contact_); // Injecting the touch down on screen
Sleep(20);
}
// Lifts the touch input UP
for (int c=0;c<5;c++)
{
POINTER_TOUCH_INFO &contact=contact_[c];
contact.pointerInfo.pointerFlags = POINTER_FLAG_INRANGE | POINTER_FLAG_UP;
}
InjectTouchInput(5, contact_); // Injecting the touch down on screen
Sleep(10);
}

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
Drag(1300,500);
}

最佳答案

几点:

确保 InitializeTouchInjection 返回 TRUE

请注意,TOUCH_FEEDBACK_DEFAULT笔和触摸控制面板中的设置影响,因此请改用 TOUCH_FEEDBACK_INDIRECT,因为这会覆盖这些选项。

关于visual-c++ - 为什么在 WIN8 下使用 Touch Injection API 时只能注入(inject)一次触摸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20875283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com