我想将我的手写数学符号识别应用程序与 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/