PDA

Click to See Complete Forum and Search --> : Mouse Position


XMortal
Nov 29th, 1999, 08:08 PM
How do i get the position of the mouse??

i wanna make a second cursor thing follow it round according to its position

frivolous i know but any help would be appreciated

MartinLiss
Nov 29th, 1999, 08:38 PM
Put this in the MouseMove event of your form and you'll get the idea. Debug.Print "X coordinate is " & X & " Y coordinate is " & Y BTW I think you will need to put code in all of your form's objects as well as the form.

------------------
Marty

[This message has been edited by MartinLiss (edited 11-30-1999).]

MicahCarrick
Nov 30th, 1999, 12:48 AM
Also, as Aaron showed me in a question I posted earlier, the GerCursorPos API will return the position of the cursor in pixels with reference to the top left corner of the screen. Then, although I may be wrong, I've only been experimenting for a couple hours with this, you can multiply the result by 15 to get a value in twips.

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Type POINTAPI
x As Long
y As Long
End Type

Private Sub Form_Load()
Timer1.enabled = True
Timer1.interval = 100
End Sub

Private Sub Timer1_Timer()
Dim tPos as POINTAPI
Call GetCursorPos(tPos)
Label1.Caption = "Pixels: " & tPos.x & "," & tPos.y
Label2.Caption = "Twips: " & Str(tPos.x * 15) & "," & Str(tPos.y * 15)
End Sub


This, as far as my own experiments have me thinking, will have the two labels showing the mouse's current position, one in pixels and one in twips.

Hope that is of some help to ya.

This

------------------
Micah Carrick
Ordinary joe with a new found passion for code.
http://micah.carrick.com
micah@carrick.com

Yonatan
Nov 30th, 1999, 03:39 AM
Actually, depending on the current screen resolution, there aren't always 15 twips in a pixel. To make it always correct, use the ScaleX and ScaleY functions:

Replace:
1) tPos.x * 15
2) tPos.y * 15
With:
1) ScaleX(tPos.x, vbPixels, vbTwips)
2) ScaleY(tPos.y, vbPixels, vbTwips)

------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
AIM: RYoni69

MicahCarrick
Nov 30th, 1999, 03:43 AM
Oh really? Cool good to know. That makes sence ... duh :)

------------------
Micah Carrick
Ordinary joe, only not named joe.
http://micah.carrick.com
micah@carrick.com

XMortal
Nov 30th, 1999, 06:59 AM
cheers guys, that helped a lot, all i needed was something that said where it was so i could feed back a negative value of the position to have the cursor mirrored across a line.

i am having difficulty when its over an object and incase any one decides to try it, you get a very funky result when you put something like

public sub picture1_MouseMove(button as ........)

picture1.left = (3000 - x ) + picture1.width
picture1.top = (3000 - x ) + picture1.height
end sub

public sub form1_resize()
form1.width = 6000
form1.height = 6000
end sub

i found that thats how you make the button avoid the cursor.

funkheads
Nov 30th, 1999, 07:42 PM
ok...this probably sounds ridiculous, but i am curious how you would find the mouse's position with respect to the form.top and form.left. i'm sure it is just a little math to be done, but for some reason i can't think of how to do it. i think my brain is fried from the all-nighter i just pulled trying to get this program written for the class i have in 3 hours.

Aaron Young
Nov 30th, 1999, 09:08 PM
You could Convert the Forms Top, Left Properties to Pixels and Subtract them from the X/Y Values.

Or you could use the ScreenToClient API passing the X/Y Coords and a Window Handle to the Form.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net