参考 緑のバイク様 http://homepage3.nifty.com/midori_no_bike/CS/ ユーザ入出力>マウスの自動操作 2012/05/27記事作成、引用
using System.Runtime.InteropServices; [DllImport("user32.dll")] extern static uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize); [StructLayout(LayoutKind.Sequential)] struct INPUT { public int type; public MOUSEINPUT mi; } [StructLayout(LayoutKind.Sequential)] struct MOUSEINPUT { public int dx; public int dy; public int mouseData; public int dwFlags; public int time; public IntPtr dwExtraInfo; } const int MOUSEEVENTF_LEFTDOWN = 0x0002; // 左ボタン Down const int MOUSEEVENTF_LEFTUP = 0x0004; // 左ボタン Up private void click() { //struct 配列の宣言 INPUT[] input = new INPUT[2]; //左ボタン Down input[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN; //左ボタン Up input[1].mi.dwFlags = MOUSEEVENTF_LEFTUP; //イベントの一括生成 SendInput(2, input, Marshal.SizeOf(input[0])); }下記でメソッドを呼び出すと
クリックされる
click();