Created
April 9, 2020 12:35
-
-
Save kusa-mochi/a3d93d03eeb226b407ed44c104feedbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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