【发布时间】:2011-07-25 10:43:30
【问题描述】:
我正在处理一个需要使用操纵杆 (DirectInput) 来控制 wpf 应用程序内的鼠标指针的项目。我需要能够按下/释放鼠标按钮以及可能在屏幕上拖动。最好这应该实际控制鼠标,允许使用操纵杆来控制其他应用程序。我已经在 DirectInput 方面搞定了一切,但我在鼠标拖动交互方面遇到了问题。
这就是我左键按下的方式:
[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, ref Input pInputs, int cbSize);
...
var aInput = new Input {
type = 0x0,
mouse = new MouseInput {
dwFlags = 0x6,
dwExtraInfo = 0,
mouseData = 0,
time = 0
}
};
SendInput(1, ref aInput, 28);
其中Input和MouseInput如下:
[StructLayout(LayoutKind.Explicit)]
public struct Input {
[FieldOffset(0)]
public int type; // 4
[FieldOffset(4)]
public MouseInput mouse; // 24
}
[StructLayout(LayoutKind.Explicit)]
public struct MouseInput {
[FieldOffset(0)]
public int dx; // 4
[FieldOffset(4)]
public int dy; // 4
[FieldOffset(8)]
public int mouseData; // 4
[FieldOffset(12)]
public int dwFlags; // 4
[FieldOffset(16)]
public int time; // 4
[FieldOffset(20)]
public int dwExtraInfo; // 4
};
此方法适用于鼠标左/右键按下,System.Windows.Forms.Cursor.Position 适用于鼠标移动,但我不确定如何设置鼠标拖动。有什么指点吗?
【问题讨论】: