Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7962
  • Last Modified:

VBScript : How to get the cursor coordinates

I have  VB code which will get me the cursor x and y coordinates. I have use 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.

Note : I need a vb script code which will be executed in vbs file.


0
sangack
Asked:
sangack
  • 3
  • 3
  • 2
  • +3
1 Solution
 
cristy56Commented:
As far as I remembered. standard win 32 DLLs cannot be used in ASP. asp can only use Activex DLLs but there's a way around this... Create you own Activex DLL using Visual Basic and encapsulate the functiions of your original dll


Cristy

0
 
cristy56Commented:
Compile your VB6 as an ActiveX DLL, register it on the server with regsvr32.exe...

then from ASP page create the object using the ProgID (e.g.) :

<%
        set obj = Server.CreateObject("GetTimeDLL.GetTime")
        varTime = obj.GetTheTime
        response.write varTime
        set obj = nothing
%>

========================================

Cristy
0
 
TyzerCommented:
If its for a webpage, why dont u use this small bit of javasript code.. its much lighter that using objects,dlls' ..

<input type=text name=x value=""> <input type=text name=y value="">

<script>
var oX = document.getElementById('x')
var oY = document.getElementById('y')
function fnJSWriteCoords(){
      oX.value = event.clientX;
      oY.value = event.clientY;
}

document.onmousedown = fnJSWriteCoords
</script>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
vnvkCommented:
Using Javascript is much easier and also no issues of security levels when you are dealing with web pages. Activex dlls may get blocked some times based on the security level.

I suggest you follow javascript if possible, ie. if not a must as per specifications to use Actvex dlls
0
 
sangackAuthor Commented:
I am using a Testing tool to test my application. My testing tool will allow only running vbs files.

So I need to execute these function in vbs file and get the coordinates.

Hope you all can understand my problem.

Is there any posibility to run as a vbs file????? if so, write the vbs code.
0
 
ZvonkoSystems architectCommented:
0
 
TyzerCommented:
What kind of testing tool are you using ? Just curious.. never heard of something like that..
Testing tool or not, i'd still go with the javascript.. just open the page in your webbrowser , see if there is no javascript error-popup.. and ur finished!
0
 
sangackAuthor Commented:
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
 
ZvonkoSystems architectCommented:
That is VB code, not VBScript. So your problem is still not solved.
You cannot access DLL functions without those DynamicWrapper dll enabled on your machine (I have not tested that DLL).
0
 
sangackAuthor Commented:
ya its true...

I was searching for VBScript code because my Testing tool will accept only vbs file. It can as well call dll too. so iam writing a dll with the above and trying to call it from my tool.

I just posted the Vb code FYi. May be I am wrong in addressing it. sorry!!!!


0
 
ZvonkoSystems architectCommented:


My proposal is:  PAQ with points refunded

This thread contains enough good stuff worth to be kept in the knowledge base.
0
 
moduloCommented:
PAQed with points refunded (300)

modulo
Community Support Moderator
0

Featured Post

Technology Partners: 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!

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now