ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   capturing mouse positions at any moment (https://www.excelbanter.com/excel-programming/299864-capturing-mouse-positions-any-moment.html)

Shrinu

capturing mouse positions at any moment
 
Hi,

I need to find out the position of a mouse at any given moment , i.e
without any event happening, is this possible. If yes ,how can i do
that. Please help me on this.
Thanks in advance.

Regards
Shrinu

Frank Kabel

capturing mouse positions at any moment
 
Hi
AFAIK not possible on a worksheet within Excel / VBA

--
Regards
Frank Kabel
Frankfurt, Germany


Shrinu wrote:
Hi,

I need to find out the position of a mouse at any given moment , i.e
without any event happening, is this possible. If yes ,how can i do
that. Please help me on this.
Thanks in advance.

Regards
Shrinu



Bob Phillips[_6_]

capturing mouse positions at any moment
 
Hi Shrinu,

Here is some code to return the mouse position as a simple function .

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

Private Type POINTAPI
x As Long
y As Long
End Type

Sub test()
Dim pPosition As POINTAPI
Dim lReturn As Long

lReturn = GetCursorPos(pPosition)
MsgBox "Cursor position is:" & vbCrLf & _
"x co-ordinate: " & pPosition.x & vbCrLf & _
"y co-ordinate: " & pPosition.y

End Sub

I also have some code that dynamically returns the mouse position into the
status bar. Post back if that would be useful.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Shrinu" wrote in message
m...
Hi,

I need to find out the position of a mouse at any given moment , i.e
without any event happening, is this possible. If yes ,how can i do
that. Please help me on this.
Thanks in advance.

Regards
Shrinu




Frank Kabel

capturing mouse positions at any moment
 
Hi Bob
I should have thought that you'll provide some API calls :-)
What kind of event are you using to update the satus bar? OnTime
method?

--
Regards
Frank Kabel
Frankfurt, Germany


Bob Phillips wrote:
Hi Shrinu,

Here is some code to return the mouse position as a simple function .

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

Private Type POINTAPI
x As Long
y As Long
End Type

Sub test()
Dim pPosition As POINTAPI
Dim lReturn As Long

lReturn = GetCursorPos(pPosition)
MsgBox "Cursor position is:" & vbCrLf & _
"x co-ordinate: " & pPosition.x & vbCrLf & _
"y co-ordinate: " & pPosition.y

End Sub

I also have some code that dynamically returns the mouse position
into the status bar. Post back if that would be useful.


"Shrinu" wrote in message
m...
Hi,

I need to find out the position of a mouse at any given moment ,

i.e
without any event happening, is this possible. If yes ,how can i do
that. Please help me on this.
Thanks in advance.

Regards
Shrinu



Bob Phillips[_6_]

capturing mouse positions at any moment
 
Hi Frank,

No I tend to eschew OnTime, and use Windows Timer and callbacks to write to
the status bar.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Frank Kabel" wrote in message
...
Hi Bob
I should have thought that you'll provide some API calls :-)
What kind of event are you using to update the satus bar? OnTime
method?

--
Regards
Frank Kabel
Frankfurt, Germany


Bob Phillips wrote:
Hi Shrinu,

Here is some code to return the mouse position as a simple function .

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

Private Type POINTAPI
x As Long
y As Long
End Type

Sub test()
Dim pPosition As POINTAPI
Dim lReturn As Long

lReturn = GetCursorPos(pPosition)
MsgBox "Cursor position is:" & vbCrLf & _
"x co-ordinate: " & pPosition.x & vbCrLf & _
"y co-ordinate: " & pPosition.y

End Sub

I also have some code that dynamically returns the mouse position
into the status bar. Post back if that would be useful.


"Shrinu" wrote in message
m...
Hi,

I need to find out the position of a mouse at any given moment ,

i.e
without any event happening, is this possible. If yes ,how can i do
that. Please help me on this.
Thanks in advance.

Regards
Shrinu





keepITcool

capturing mouse positions at any moment
 
Be aware of 1 thing though:

When you use the coords from this api (or an office.commandbar) these
will be given with a actual screenres of 96ppi.

Excel's coordinates from say .cells(3).Left will be given with a default
of 72ppi ... more like pixels :(

this means that any coords you use to get or set directly from excel in
'POINTS' need to be multiplied by 96/72

Also Excel's coord (0.0) from say a worksheet start in the usable area
(depending on whether toolbars are docked etc)

'Get the starting point of the xlDesktop (Usable Area)
Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As
Long, lpPoint As POINTAPI) As Long

dim p as pointapi
dim lhnd as long
dim lret as long
lhnd = application.hWnd 'This works for xlXP and newer
lRet = ClientToScreen(lHnd, p) 'This fills p


hth...



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Bob Phillips" wrote:

Hi Shrinu,

Here is some code to return the mouse position as a simple function .

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

Private Type POINTAPI
x As Long
y As Long
End Type

Sub test()
Dim pPosition As POINTAPI
Dim lReturn As Long

lReturn = GetCursorPos(pPosition)
MsgBox "Cursor position is:" & vbCrLf & _
"x co-ordinate: " & pPosition.x & vbCrLf & _
"y co-ordinate: " & pPosition.y

End Sub

I also have some code that dynamically returns the mouse position into
the status bar. Post back if that would be useful.




All times are GMT +1. The time now is 05:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com