Solved

Find the x & y coordinates in a webpage

Posted on 2004-09-03
12
1,751 Views
Last Modified: 2013-12-16
Hi,

I am working for QA Automation. We are using VBScript in our automation tool. I have a problem.

I need to capture the x and y co-ordinates of the point where the current focus is. For example if a node of a tree has been selected and the focus is on it. I need to findout the x and y co-ordinates of that node. Will this be possible in VBSCript. Can anyone help me out.

Note : I need a VBScript code which will get me the coordinates of my cursor position.

Thanks in advance.
0
Comment
Question by:sangack
  • 5
  • 5
12 Comments
 
LVL 2

Expert Comment

by:SeanLWilliams
ID: 11979300
use the mouseevent  onMouseOver on a any particular object your trying to find then
use the following in a js routine


var mousex = window.event.x;        // mouse location capture event
var mousey = window.event.y;        // mouse location capture event

0
 

Author Comment

by:sangack
ID: 11979316
I am using keyboard Down key to navigate to the specified node of a Tree control. Now my cursor is highlighted in that position, my mouse remains at different position.

I just want to get my cursor coordinates so that I will take my mouse to the cursor position using my Automation Tool.

How to get the cursor coordinates???

Note : I need a VBScript code which will get me the coordinates of my cursor position.

*************************************************

I can use user32.dll and get the x y co ordinates.

extern.declare micHwnd, "GetCursorPos", "user32.dll", "GetCursorPos"

GetCursorPos(LPOINT lpPoint)

But this LPOINT is giving me Error

0
 
LVL 2

Expert Comment

by:SeanLWilliams
ID: 11979324
This might be a little better

fields T1 and T2  ( t1 and t2 repectively in the javascript)
are purely for displaying the values
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 3</title>
</head>
<script language = "javascript">
      function getMousePos(){
            var t1 = document.getElementById("T1")
            var t2 = document.getElementById("T2")

            var mousex = window.event.x;        // mouse location capture event
            var mousey = window.event.y;        // mouse location capture event

            t1.value = mousex
            t2.value = mousey

            }
            
 document.onmousemove = getMousePos;

</script>
<body>


<input type="text" id="T1" name="T1" size="20">
<input type="text" id="T2" name="T2" size="20">


</body>

</html>
0
 

Author Comment

by:sangack
ID: 11979338
My mouse remains idle at different position, only my cursor moves.

I need the cursor coordinates????
0
 
LVL 2

Expert Comment

by:SeanLWilliams
ID: 11979356
apologies,  assumed mouse as being cursor
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Expert Comment

by:SeanLWilliams
ID: 11979378
could you not do something very basic with keypress events    if left  x-1,  right x+1   up  y-1  down y+1?

0
 

Author Comment

by:sangack
ID: 11979406
See I have a code in Visual basic which will talk to user32.dll and get the co ordinates.

Here it is :

*********************************************************
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
*********************************************************

But I want this to work in a VBSCRIPT file. ie vbs file. If you could make it happen, appreciated!!!
0
 
LVL 2

Expert Comment

by:SeanLWilliams
ID: 11979437
why not create  a vb  dll  and then refer to it as a seperate function

look on  4guysfromrolla   for information about formatting  ( i know it 's not )   but they explain how to creat a dll in vb nd then referencing it through asp,  I use it in mine at work,   but don't have the code here,  and me baby is lying asleep in my arms, so typing one handed

0
 

Author Comment

by:sangack
ID: 11987101
Your sugession is good, but can't implement as I need to find the solution in VBSCRIPT only.

Any help in building in VBSCRIPT appreciated!!!
0
 

Author Comment

by:sangack
ID: 12023850
Here is the VB code which I need.

For your reference....

*********************************************************************Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Type GUITHREADINFO
    cbSize As Long
    flags As Long
    hwndActive As Long
    hwndFocus As Long
    hwndCapture As Long
    hwndMenuOwner As Long
    hwndMoveSize As Long
    hwndCaret As Long
    rcCaret As RECT
End Type

Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetGUIThreadInfo Lib "user32" (ByVal dwthreadid As Long, lpguithreadinfo As GUITHREADINFO) As Long

Public Sub GetFocusedControlPos(ByRef x As Integer, ByRef y As Integer)
   Dim RetInfo As GUITHREADINFO
   Dim WndHandle As Long
   Dim SelectedPID As Long
   Dim MyRect As RECT
   Dim lpClassName As String
       
   'Get active window
   WndHandle = GetForegroundWindow()
   'Get GUI PID of the selected thread
   SelectedPID = GetWindowThreadProcessId(WndHandle, 0)

   RetInfo.cbSize = LenB(RetInfo)
   
   If GetGUIThreadInfo(SelectedPID, RetInfo) = 0 Then
        MsgBox "Error while calling the function!"
        Exit Sub
    End If
   
     'Get window rectangle
   GetWindowRect RetInfo.hwndFocus, MyRect

    lpClassName = Space(256)
    'retrieve the class name
    RetVal = GetClassName(RetInfo.hwndFocus, lpClassName, 256)

    MsgBox lpClassName
   
   x = MyRect.Left
   y = MyRect.Top
End Sub

Private Sub Timer1_Timer()
   Dim x As Integer
   Dim y As Integer

   GetFocusedControlPos x, y
   Me.Caption = x & " " & y
End Sub

*********************************************************************
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12743120
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Classic ASP - cannot find folder on the server 5 29
CSS Question.. 3 72
JQuery Date Time picker not showing 29 95
SQL Filter Question 8 69
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now