首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模拟鼠标移动

模拟鼠标移动
EN

Stack Overflow用户
提问于 2013-08-22 10:38:05
回答 1查看 5K关注 0票数 3

我有ListView和图像在我的UserControl中。当我带来的图片,我已经是重画图片时,从图片中删除鼠标滋养老。但是当我带着第二次出现在同一幅画上的时候,我不想重画,而是当我拿走了ListView的小教堂,再一次,那伏珠作品。我以为我能做一只模仿老鼠。或者告诉我更好的事。

代码语言:javascript
复制
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);

它起作用了,但我看到一丝老鼠的微光。

EN

回答 1

Stack Overflow用户

发布于 2013-08-22 11:32:40

为了模拟鼠标的移动,它的按钮点击等等,您可以尝试mouse_event的API函数。小心点,它适用于微键而不是像素。

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646260(v=vs.85).aspx

代码语言:javascript
复制
[DllImport("User32.dll",
            EntryPoint = "mouse_event",
            CallingConvention = CallingConvention.Winapi)]
internal static extern void Mouse_Event(int dwFlags,
                                        int dx,
                                        int dy,
                                        int dwData,
                                        int dwExtraInfo);

[DllImport("User32.dll",
            EntryPoint = "GetSystemMetrics",
            CallingConvention = CallingConvention.Winapi)]
internal static extern int InternalGetSystemMetrics(int value);
...
    
// Move mouse cursor to absolute position to_x, to_y and make left button click:
int to_x = 500;
int to_y = 300;

int screenWidth = InternalGetSystemMetrics(0);
int screenHeight = InternalGetSystemMetrics(1);
       
// Mickey X coordinate
int mic_x = (int) System.Math.Round(to_x * 65536.0 / screenWidth);
// Mickey Y coordinate
int mic_y = (int) System.Math.Round(to_y * 65536.0 / screenHeight);
    
// 0x0001 | 0x8000: Move + Absolute position
Mouse_Event(0x0001 | 0x8000, mic_x, mic_y, 0, 0);
// 0x0002: Left button down
Mouse_Event(0x0002, mic_x, mic_y, 0, 0);
// 0x0004: Left button up
Mouse_Event(0x0004, mic_x, mic_y, 0, 0);
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18378142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档