連打ツールの作り方です
dllファイルを使用するので、プログラムの一番上に
Imports System.Runtime.InteropServices
を記述してください
Imports System.Runtime.InteropServicesPublic Class Form1
......
という感じになります
そして、まずは前提の、定義をします
Public Class Form1のあとに
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Private Shared Sub SendInput( _
ByVal nInputs As Integer, _
ByRef pInputs As INPUT, _
ByVal cbsize As Integer)
End Sub
Dim X As Integer
Dim Y As Integer
Dim Pos As Point = Windows.Forms.Cursor.Position
Private Structure MOUSEINPUT
Public dx As Integer
Public dy As Integer
Public mouseData As Integer
Public dwFlags As Integer
Public time As Integer
Public dwExtraInfo As Integer
End Structure
Private Structure INPUT
Public type As Integer
Public mi As MOUSEINPUT
End Structure
Private Const INPUT_MOUSE = 0 ' マウスイベント
Private Const MOUSEEVENTF_MOVE = &H1
Private Const MOUSEEVENTF_ABSOLUTE = &H8000
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Dim inp As INPUT = New INPUT
を記述してください
これで定義の記述は終了です
使用する方法は、まず
マウスカーソルの移動をしたいときは、
inp.type = INPUT_MOUSE
inp.mi.dwFlags = _
MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE
inp.mi.dx = _
x座標 * (65535 / Screen.PrimaryScreen.Bounds.Width)
inp.mi.dy = _
y座標 * (65535 / Screen.PrimaryScreen.Bounds.Height)
inp.mi.mouseData = 0
inp.mi.dwExtraInfo = 0
inp.mi.time = 0
SendInput(1, inp, Marshal.SizeOf(inp))
これでマウスカーソルの移動ができます
たとえば、画面の左上、x=0 y=0をクリックしたいときは
ボタン1に割り当てると考えて
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
inp.type = INPUT_MOUSE
inp.mi.dwFlags = _
MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE
inp.mi.dx = _
0 * (65535 / Screen.PrimaryScreen.Bounds.Width)
inp.mi.dy = _
0 * (65535 / Screen.PrimaryScreen.Bounds.Height)
inp.mi.mouseData = 0
inp.mi.dwExtraInfo = 0
inp.mi.time = 0
SendInput(1, inp, Marshal.SizeOf(inp))
End Sub
となります
今回はここまでです
質問等ありましたら、コメント欄までお願いします
