Solved

Find the x & y coordinates in a webpage

Posted on 2004-09-03
12
1,864 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
[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
  • 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to insert an Iframe into 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 : Open Page or Post…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

724 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