Skip to content

Instantly share code, notes, and snippets.

@kusa-mochi
Created April 9, 2020 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kusa-mochi/a3d93d03eeb226b407ed44c104feedbb to your computer and use it in GitHub Desktop.
Save kusa-mochi/a3d93d03eeb226b407ed44c104feedbb to your computer and use it in GitHub Desktop.
Win32Point mousePosition = new Win32Point {
X = 0,
Y = 0
};
// マウスポインタの現在位置を取得する。
NativeMethods.GetCursorPos (ref mousePosition);
// マウスポインタの現在位置でマウスの左ボタンの押し下げ・押し上げを連続で行うためのパラメータを設定する。
INPUT[] inputs = new INPUT[] {
new INPUT {
type = NativeMethods.INPUT_MOUSE,
ui = new INPUT_UNION {
mouse = new MOUSEINPUT {
dwFlags = NativeMethods.MOUSEEVENTF_LEFTDOWN,
dx = mousePosition.X,
dy = mousePosition.Y,
mouseData = 0,
dwExtraInfo = IntPtr.Zero,
time = 0
}
}
},
new INPUT {
type = NativeMethods.INPUT_MOUSE,
ui = new INPUT_UNION {
mouse = new MOUSEINPUT {
dwFlags = NativeMethods.MOUSEEVENTF_LEFTUP,
dx = mousePosition.X,
dy = mousePosition.Y,
mouseData = 0,
dwExtraInfo = IntPtr.Zero,
time = 0
}
}
}
};
// 設定したパラメータに従ってマウス動作を行う。
NativeMethods.SendInput (2, ref inputs[0], Marshal.SizeOf (inputs[0]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment