[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to get the x and y coordinates of the cursor

Posted on 2004-09-06
7
Medium Priority
?
1,023 Views
Last Modified: 2012-08-14
I have  VB code which will get me the cursor x and y coordinates. I have used the user32.dll to fetch the coordinates. Here is that code...

*********************************************************
Private Declare Sub GetCursorPos Lib "user32.dll" (lpPoint As POINTAPI)

Private Type POINTAPI
X As Integer
Y As Integer
End Type
Private mPosition As POINTAPI

Call GetCursorPos(mPosition)
msgbox mPosition.X
msgbox mPosition.Y
*********************************************************

Now I need the same code to be executed in a vbs file ie., as a VBScript file. Can anyone tell me how to use windows api in vbs file and give me the vbs code for the above situation.

Question 1. I get the x and y coordinates when I run the code in VB 6.0, but a reference memory error is also poping up and closing VB.

Question 2. I need a vb script code which on executing the vbs file should give me the coordinates.



0
Comment
Question by:sangack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11988194
It should be sthg like this

  X = window.event.clientX
  Y = window.event.clientY

You should put htis in function and caal it on mousemove event
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 11988198
You can't use API's directly in VBScript, the best you can do is create a DLL that wraps the API call and then use that in your VB file.
0
 

Author Comment

by:sangack
ID: 11988251
Hi Carl_tawn

Can you help me in building that dll? I am not that much expert in VB.

Great that u can paste the dll code or send me to
sanjaykumar.b@gmail.com

Sanjay
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Accepted Solution

by:
aelatik earned 2000 total points
ID: 11988265
I don't think you can access the getcursor api in vbscript. You will have to write a DLL to do that.

Create a new active x dll and paste the following code in it : ( Make the projectname : CURSOR and call the class POSITIONS )

Private Type POINTAPI
    X As Long
    Y As Long
End Type

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

Dim MPOS As POINTAPI

Public Property Get X() As Long
    X = MPOS.X
End Property

Public Property Get Y() As Long
    Y = MPOS.Y
End Property

Private Sub Class_Initialize()
    Call GetCursorPos(MPOS)
End Sub

Now compile the DLL and place it in your system32 directory and register it.

You can now access it through vbscript by typing :

Dim POS
Set POS = Wscript.CreateObject("CURSOR.POSITION")
Wscript.echo "Position of X =" & POS.X
Wscript.echo "Position of Y =" & POS.Y
Set POS = Nothing
0
 
LVL 14

Expert Comment

by:aelatik
ID: 11988271
I can email the compiled dll i you like ?
0
 

Author Comment

by:sangack
ID: 11988438
aelatik

You soultion is great. It works fine.
But there is one small modification. Object should be created as ("CURSOR.POSITIONS")

Another Doubt in it. While executing the same it gives the mouse coordinates, but I need the coordinates of the current focus area in the screen.

For Example, in the desktop if a folder is selected ie., highlighted I need the coordinates of the highlighted folder rather than my mouse coordinates.

Hope you can understand.
0
 

Author Comment

by:sangack
ID: 11989183
aelatik

I have posted a Question with title " Is there any API which gives the current focus area's coordinates? "  under "Languages" Topic.

Hope you can help me in that .

Sanjay Kumar
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question