作成 2013.09.28
更新 2013.09.28
C# でマウスカーソルの動作シミュレーション
コードサンプル
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public class MouseSimulate {
	private const UInt32 MOUSEEVENTF_MOVE = 	0x0001;
	private const UInt32 MOUSEEVENTF_LEFTDOWN =	0x0002;
	private const UInt32 MOUSEEVENTF_LEFTUP =	0x0004;
	private const UInt32 MOUSEEVENTF_RIGHTDOWN =	0x0008;
	private const UInt32 MOUSEEVENTF_RIGHTUP =	0x0010;
	private const UInt32 MOUSEEVENTF_MIDDLEDOWN =	0x0020;
	private const UInt32 MOUSEEVENTF_MIDDLEUP =	0x0040;
	private const UInt32 MOUSEEVENTF_WHEEL =	0x0800;
	private const UInt32 MOUSEEVENTF_ABSOLUTE =	0x8000;

	[DllImport("user32.dll")]
	private static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, uint dwExtraInf);

	public void SimulateLeftClick(Int32 x, Int32 y){
		Cursor.Position = new Point(x, y);
		mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
		mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
	}
}
参考
タグ: CSharp

©2004-2017 UPKEN IPv4