我想将手写数学符号识别的应用程序与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时,一切都运行得很好。
有没有人知道如何解决它?
答案 0 :(得分:1)
我已经使用以下功能解决了问题:
[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);
我称之为控制鼠标按钮和鼠标移动,它完美无缺。