[英]SendInput mouse time
因此,基本上我想做的就是將鼠標平穩地移動到中心。 我在這里擁有的功能正常,但是它將光標立即傳送到中心。
另外,如果將input.mi.time
設置為大於0的值,則會使PC進入睡眠狀態。 誰能進一步解釋它的作用? 該文檔並沒有真正為我澄清。
#include <iostream>
#include <Windows.h>
int screenWidth;
int screenHeight;
void moveMouse(int x, int y)
{
POINT mouseCoords;
GetCursorPos(&mouseCoords);
INPUT input;
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
input.mi.dwExtraInfo = NULL;
input.mi.mouseData = NULL;
input.mi.dx = -mouseCoords.x + x;
input.mi.dy = -mouseCoords.y + y;
input.mi.time = NULL;
SendInput(1, &input, sizeof(INPUT));
}
void main()
{
screenWidth = GetSystemMetrics(SM_CXSCREEN);
screenHeight = GetSystemMetrics(SM_CYSCREEN);
int middleOfScreenX = screenWidth / 2;
int middleOfScreenY = screenHeight / 2;
moveMouse(middleOfScreenX, middleOfScreenY);
}
您遇到的問題與Raymond Chen在2012年的帖子中描述的完全一樣:
當您使用SendInput合成輸入時,您也在合成時間戳 (重點是我的):
客戶在使用SendInput函數模擬用於自動測試目的的拖放操作時報告了問題。
是的,所有事件都立即發生,因為您一次提交了所有事件。
MOUSEINPUT
結構中的time
字段不用於引入回放延遲 。
解決方案也在發布中:
如果要發生三個輸入事件,它們之間的延遲為500ms,則需要調用3次SendInput,兩次調用之間的延遲為500ms。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.