c# - 在数学输入面板中模拟鼠标移动 (Windows 7)

标签 c# winapi math windows-7 mouseevent

我想将我的手写数学符号识别应用程序与 Windows 7 中包含的数学输入面板 (MIP) 进行比较。我有一个代表不同数学公式的记录鼠标笔划的库,我需要将它们发送到 MIP 以衡量其表现。

我尝试模拟鼠标移动,但它不起作用。

以下是我使用的常量和导入方法:

const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")]
static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, UIntPtr dwExtraInfo);

这就是代码本身:

IntPtr windowHandle = FindWindow("MathInput_Window", "");
SetForegroundWindow(windowHandle);

Cursor.Position = new Point(600, 700);
mouse_event(MOUSEEVENTF_LEFTDOWN, 600, 700, 0, UIntPtr.Zero);

for (int x = 600; x <= 650; x++)
{
    Cursor.Position = new Point(x, 700);
}

for (int y = 700; y <= 750; y++)
{
    Cursor.Position = new Point(650, y);
}

mouse_event(MOUSEEVENTF_LEFTUP, 650, 750, 0, UIntPtr.Zero);

但我唯一得到的是位置 [600,700] 处的一个点。有趣的是,当我使用 MSPaint 而不是 MIP 时,一切都运行良好。

有人知道如何解决吗?

最佳答案

我已经使用以下函数解决了这个问题:

[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);

我调用它来控制鼠标按钮点击和鼠标移动,它工作得很好。

关于c# - 在数学输入面板中模拟鼠标移动 (Windows 7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3157557/

相关文章:

c# - WPF ListBox 在用户滚动时生成项目

c# - NLog.Extensions.Logging 结构化日志

C# 放在哪里查看具体信息?

c++ - 带有 RRF_RT_REG_SZ 的 RegSetValueEx 在注册表中生成 REG_EXPAND_SZ?

javascript - 在 64 位环境中加载 32 位进程

delphi - 从 IShellLibrary 添加、删除文件夹

java - 我无法理解 PhotoView 的 getDisplayRect() 实际返回的内容(构建 android 照片裁剪工具)

c# - 简单的数学题

c# - 使用 Dapper 多次执行存储过程?

php - 浮点后最多显示 2 位数字...仅当它是超过 2 个 float 字的 float 时