반응형
* VBNET API 를 이용한 마우스 커서 좌표 이동 및 이동한 위치 자동 클릭 이벤트 예제...
전체 소스 코드
Form1.vb
Imports System.Runtime.InteropServices
Public Class Form1
'API선언...
<DllImport("user32")> _
Shared Function SetCursorPos(ByVal x As Int32, ByVal y As Int32) As Int32
End Function
Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, _
ByVal dx As Integer, _
ByVal dy As Integer, _
ByVal cButtons As Integer, _
ByVal dwExtaInfo As Integer)
<DllImport("user32")> _
Public Shared Function GetCursorPos(ByRef pt As Point) As Int32
End Function
Const MOUSE_LBUTTONDOWN As Integer = &H2
Const MOUSE_LBUTTONUP As Integer = &H4
Dim pi As Point = New Point()
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
timer1.Start()
End Sub
Protected Overrides Sub OnClosed(ByVal e As System.EventArgs)
MyBase.OnClosed(e)
timer1.Stop()
End Sub
Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
'Start
If (IsInt(txtX.Text) = 0) And (IsInt(txtY.Text) = 0) Then
MessageBox.Show("TextBox Value Not Number !!! Check Please...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtX.Focus()
Return
End If
'Cursor Location
SetCursorPos(Convert.ToInt32(txtX.Text), Convert.ToInt32(txtY.Text))
'Mouse Left Button Click
mouse_event(MOUSE_LBUTTONDOWN, 0, 0, 0, 0) 'Mouse LEFT Down Event
mouse_event(MOUSE_LBUTTONUP, 0, 0, 0, 0) 'Mouse LEFT UP Event
End Sub
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
'Result
MessageBox.Show("API Mouse Button Click Success...", "확 인", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End Sub
Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer1.Tick
If GetCursorPos(pi) Then
lblX.Text = pi.X.ToString()
lblY.Text = pi.Y.ToString()
End If
End Sub
Private Function IsInt(ByVal ob As Object) As Integer
If ob Is Nothing Then
Return 0
End If
Dim iCheck As Integer = 0
Dim bCheck As Boolean = Integer.TryParse(ob.ToString(), iCheck)
If Not bCheck Then
Return 0
End If
Return iCheck
End Function
End Class
*예제 결과
https://kdsoft-zeros.tistory.com/163
https://kdsoft-zeros.tistory.com/77
https://kdsoft-zeros.tistory.com/164
반응형
'VB.NET Programming' 카테고리의 다른 글
[VBNET] [WMI] 실시간 메모리 사용량 체크 (Memory Check) - Progressbar (0) | 2020.03.18 |
---|---|
[VBNET] 제어판 프린터(Printer) 목록 불러오기 (0) | 2020.03.16 |
[VBNET] [API] 마우스 커서 좌표 얻어오기 (0) | 2020.03.10 |
[VBNET] [API] 한/영 키 상태 값 구하기 (0) | 2020.03.06 |
[VBNET] 윈도우 폼(Window Form) - 폼(Form) 화면 그대로 프린트(Print) (0) | 2020.03.04 |