Step-by-Step Example - How to get the current mouse cursor position
1. Start a new project in Visual Basic. Form1 is created by default.
2. From the File Menu, choose New Module.
3. Add the following code in the General Declarations section of the new module:
Type POINTAPI \' This holds the logical cursor information x As Integer y As Integer End Type
Declare Sub GetCursorPos Lib \"User32\" (lpPoint As POINTAPI)
4. Add a timer control (Timer1) to the form.
5. Add the following code to the Form_load event:
Sub Form_Load () timer1.Interval = 100 End Sub
6. Add the following code to the Timer1_Timer event:
Sub Timer1_Timer () Dim rect As POINTAPI \' Get the current mouse cursor coordinates: Call GetCursorPos(rect) FORM1.Cls \' Print out current position on the form: Print \"Current X = \" & rect.x Print \"Current Y = \" & rect.y End Sub
7. Run the Program. You should be able to see the cursor coordinates change whenever you move the mouse around the screen.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.