Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, I want to detect a mouse event anywhere on the screen,By now Im only detecting the click inside the form:

 

Private Sub Main_MouseDown(ByVal sender As Object, ByVal e As_

System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown

If e.Button = Windows.Forms.MouseButtons.Right Then

MsgBox("Right")

End If

End Sub

 

In advance thanks!!

Posted

Done, I found a way!!

 

Option Strict On

Imports System.Windows.Forms

Imports System.Runtime.InteropServices

 

Public Class Form1

Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

 

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseMove, Label1.MouseMove, Label2.MouseMove, Label3.MouseMove

Label3.Text = "Usando los valores del parámetro: " & vbCrLf & "x= " & e.X & ", Y = " & e.Y

End Sub

 

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Dim x As Integer = Cursor.Position.X

Dim y As Integer = Cursor.Position.Y

Dim p As POINT_API

GetCursorPos(p)

Label1.Text = "Usando Cursor.Position: " & vbCrLf & "x= " & x & ", Y = " & y

Label2.Text = "Usando GetCursorPos: " & vbCrLf & "x= " & p.X & ", Y = " & p.Y

If GetAsyncKeyState(1) = 0 Then

Label4.Text = "Your Left Mouse Button Is UP"

Else

Label4.Text = "Your Left Mouse Button Is Down"

End If

If GetAsyncKeyState(2) = 0 Then

Label5.Text = "Your Right Mouse Button Is UP"

Else

Label5.Text = "Your Right Mouse Button Is Down"

End If

End Sub

End Class

 

Module WinAPI

Public Structure POINT_API

Public X As Integer

Public Y As Integer

End Structure

Public Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As POINT_API) As Boolean

End Module

Posted

Although I've never used it myself, there is a 'low level mouse hook' in windows. You might want to search on LowLevelMouseProc if you're interested.

 

As I understand it, this is a callback that is called by the OS when the mouse is operated. You can set the hook with SetWindowsHookEx.

Nothing is as illusive as 'the last bug'.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...