반응형

* VBNET API 를 이용한 마우스 커서 좌표 이동 및 이동한 위치 자동 클릭 이벤트 예제...

 

Main

전체 소스 코드

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

 

[VBNET] [API] 마우스 커서 좌표 얻어오기

* VBNET API 를 이용한 마우스 커서 좌표 얻어 오기 예제... 전체 소스 코드 Form1.vb Imports System.Runtime.InteropServices Public Class Form1 'API 선언... <dllimport("user32")> _ Public Shared Functio..</dllimport("user32")>

kdsoft-zeros.tistory.com

 

https://kdsoft-zeros.tistory.com/77

 

[VBNET] string 을 int 및 double 형으로 변환 하기, string null 체크

* string 문자열을 정수 및 실수 형으로 변환 하기 예제... 전체 소스코드 Form1.vb Public Class Form1 Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butto..

kdsoft-zeros.tistory.com

 

https://kdsoft-zeros.tistory.com/164

 

[C#] [API] Mouse Cursor Move And AutoClick Event

* C# API 를 이용한 마우스 커서 이동 및 마우스 버튼 클릭 이벤트 예제... 전체 소스 코드 Form1.cs - API 선언 함수 : mouse_event , GetCursorPos, SetCursorPos using System; using System.Collections.Gene..

kdsoft-zeros.tistory.com

 

반응형

+ Recent posts