开发者

using mouse with sendInput in C

开发者 https://www.devze.com 2023-02-01 14:47 出处:网络
I would like to programmatically move and click the mouse using the windows API in C. I have searched google high and low and can\'t find any sendInput tutorials for plain C. All I can find is C#/C++.

I would like to programmatically move and click the mouse using the windows API in C. I have searched google high and low and can't find any sendInput tutorials for plain C. All I can find is C#/C++. I have little experience with the windows API and would love a great tutorial that would cover s开发者_如何学PythonendInput! Thanks!


Hans Passant was right with C++ code being almost identical. Here's what I ended up with:

INPUT input;
input.type = INPUT_MOUSE;
input.mi.mouseData = 0;
input.mi.dx = x * (65536 / GetSystemMetrics(SM_CXSCREEN)); //x being coord in pixels
input.mi.dy =  y * (65536 / GetSystemMetrics(SM_CYSCREEN)); //y being coord in pixels
input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
SendInput(1, &input, sizeof(input));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号