Results 1 to 6 of 6

Thread: How can I make my program read the cursors location and stuff outside of program...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    2

    Post

    Okay, the subject mainly says it all:
    How do I find the cursors location and other things outside of the program window.

    Thank you,
    Hegpetz

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263
    Um, I don't know what you mean by 'other things', but use GetCursorPos api to get the cursor's position.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Getwindowrect get's the position of any window
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Addicted Member ZanM's Avatar
    Join Date
    Oct 1999
    Location
    The here and now.
    Posts
    191

    place the following declares in a module
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Public Declare Function GetWindowWord Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long) As Integer
    Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
    Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Public Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2

    Public Const SWP_NOMOVE = &H2
    Public Const SWP_NOSIZE = &H1
    Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE

    Public Type POINTAPI
    X As Long
    Y As Long
    End Type

    place this code inside a timer with an interval of 1 on a form


    Dim point As POINTAPI, pointX As Long, pointY As Long, hwndLast As Long
    Dim wHwnd As Long, pHwnd As Long, wClass As String * 100
    Dim pClass As String * 100, wTxt As String * 100, pTxt As String * 100
    Dim wTxtLen As Long, pTxtLen As Long, z As String
    On Error Resume Next
    Call GetCursorPos(point)
    pointX& = point.X
    pointY& = point.Y
    wHwnd& = WindowFromPoint(pointX&, pointY&)
    If wHwnd& <> hwndLast& Then
    Cls
    Print "Window hWnd: " & wHwnd&
    z$ = GetClassName(wHwnd&, wClass$, 100)
    Print "Window Class Name: " & Left(wClass$, z$)
    z$ = GetWindowText(wHwnd&, wTxt$, 100)
    Print "Window Caption: " & Left(wTxt$, z$)
    wTxtLen& = GetWindowTextLength(wHwnd&)
    Print "Window Text Length: " & wTxtLen&
    pHwnd& = GetParent(wHwnd&)
    If pHwnd& <> 0& Then
    Print ""
    Print "Parent Window hWnd: " & pHwnd&
    z$ = GetClassName(pHwnd&, pClass$, 100)
    Print "Parent Window Class Name: " & Left(pClass$, z$)
    z$ = GetWindowText(pHwnd&, pTxt$, 100)
    Print "Parent Window Caption: " & Left(pTxt$, z$)
    pTxtLen& = GetWindowTextLength(pHwnd&)
    Print "Parent Window Caption Length: " & pTxtLen&
    Else
    Print ""
    Print "Parent Window hWnd: N/A"
    Print "Parent Window Class Name: N/A"
    Print "Parent Window Caption: N/A"
    Print "Parent Window Caption Length: N/A"
    End If
    End If


    if the syntax correct itself from being inside here it should show you what you want and give you a good idea of how yo get more information
    Magiaus
    Visual Basic 6.0 SP5
    Visual C++ 6.0 SP5


    The only sovereign you can allow to rule you is reason.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    2

    That's good for API Spy and stuff, but here's what I need

    I need to learn how to find the x/y location of the mouse on other windows.
    For example, for Ultima Online, there is a program called UOAutoPilot, you can set locations, you click button, it "appactivate"s UO window and where'ever you click it saves the x/y then in the script area you set somethin like, Single Click at Location #1, I can easily make this program, and probably make it better, but that's what's stopping me, I can only make it read the mouses location on the window of the program.

    Thank you,
    Hegpetz

  6. #6
    Addicted Member ZanM's Avatar
    Join Date
    Oct 1999
    Location
    The here and now.
    Posts
    191

    Arrow try this

    ok you need the following

    Form name frmGetCursorPos (or whatever)

    Timer on the form
    2 labels on the form
    1 Image box

    ok now go and browse your HD find a mousepointer you like not the one you are using

    set the picture and the mouse point properties of the image box to that mouse pointer

    next place the following in the forms declares area

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

    Private Type POINTAPI
    X As Long
    Y As Long
    End Type

    Dim stdArrow as stdPicture


    ok in the timer place this code
    tmrGetIt_Timer()
    dim point as POINTAPI,pX as long,pY as long
    dim a as long
    a = GetCursorPos(point)
    pX = point.X
    pY = point.Y
    lblX = pX
    lblY = pY
    End Sub

    ok in the MouseDown of you image box place this code

    imgArrow_MouseDown(Button as integer,...,...)
    timer.enabled = true
    set stdArrow.Picture = imgArrow.Picture
    imgArrow = me.picture 'none that is
    imgArrow.MousePointer = 99
    end sub

    ok now for the mouse up ( you probably have the idea by now)

    imgArrow_MouseUp
    Timer.enabled=false
    imgArrow.picture = stdArrow.Picture
    imgArrow.MousePointer=0
    end sub

    and that will give you any point on the screen
    oh and if you want to lose the timer you can put the code from the timer in the imgArrow mouse move

    hope that gets you going if your playing a game though this may not work because of the use of openGl or DirectX preventing the form from bieng accessable I have never tried it on a game just used it to make a code generator

    if you happen to know anything about databases go to the DB section and read my post maybe you can help me.....
    Magiaus
    Visual Basic 6.0 SP5
    Visual C++ 6.0 SP5


    The only sovereign you can allow to rule you is reason.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width