Jump to content

Recommended Posts

Posted (edited)

I'm having trouble finding the mouse coordinates within a game window.

This is the working code:

Func getpos()
    $x = MouseGetPos(0)
    $y = MouseGetPos(1)
    MsgBox ( 0, "MSG", "MousePos: "& $x &", " & $y , 1 )
endfunc

The only result i get is the coordinates of the game window, no matter where the cursor is in the window.

MouseMove also failed to move the mouse in the window. However, I can move the mouse with

MouseMovePlus.

When I tried to read the mouse coordinates at a similar low level, it still didnt work!

Func _MouseGetPosPlus()
    $tPoint = DllStructCreate("long X; long Y")
    DllCall("user32.dll", "none", "GetCursorPos", "ptr", DllStructGetPtr($tPoint))
    ConsoleWrite("Cursor X position: " & DllStructGetData($tPoint, "X") & @CR)
    ConsoleWrite("Cursor Y position: " & DllStructGetData($tPoint, "Y") & @CR)
EndFunc

Can someone please help me with this? I am wondering how the game is blocking the mousecoordinates.

I think that the game might be using a software cursor. If so, is it possible to read the position?

The game is Xenimus, and can be downloaded at www.xenimus.com

Edited by zeropoint
Posted (edited)

...

your code doesn't mean anything !!! please read the helpfile

mousegetpos return an array

code corrected:

$MPos = MouseGetPos()
        MsgBox ( 0, "MSG", "MousePos: "& @CRLF& _
                                               "x: "&$MPos[0] & @CRLF& _
                                               "y: " & $MPos[1] , 1 )

second code works correctly

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 139, 43, 193, 159)
$Input1 = GUICtrlCreateInput("Input1", 8, 8, 121, 21,$ES_READONLY)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$tPoint = DllStructCreate("long X; long Y")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    DllCall("user32.dll", "none", "GetCursorPos", "ptr", DllStructGetPtr($tPoint))
    GUICtrlSetData($Input1,"x: "&DllStructGetData($tPoint, "X")&"     y: "&DllStructGetData($tPoint, "Y"))
    
WEnd
Edited by Kilhian
Posted

oops... You're right about the first code. Should be:

$MPos = _MouseGetPosPlus()
    MsgBox ( 0, "MSG", "MousePos: "& $MPos[0] &", " & $MPos[1] , 1 )

And it works on my desktop and in every other window besides the game window. When I use it in the game window, it only returns the same coordinate no matter where my mouse is inside the window...

Posted

oops... You're right about the first code. Should be:

$MPos = _MouseGetPosPlus()
    MsgBox ( 0, "MSG", "MousePos: "& $MPos[0] &", " & $MPos[1] , 1 )

And it works on my desktop and in every other window besides the game window. When I use it in the game window, it only returns the same coordinate no matter where my mouse is inside the window...

and if you refresh values in a loop ?

Where did you found the function _MouseGetPosPlus()? the right one is MouseGetPos()

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 139, 43, 193, 159)
$Input1 = GUICtrlCreateInput("Input1", 8, 8, 121, 21,$ES_READONLY)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
   $MPos = MouseGetPos()
    GUICtrlSetData($Input1,"x: "&$MPos[0]&"   y: "&$MPos[1])
    
WEnd
Posted (edited)

Ok, the code I've been posting has been retarded...

Since I can't figure out how to edit posts: :)apparently, the edit button appeared once I posted, see first post for code

My code actually compiles and runs fine on my desktop.

The issue here is that none of it works in the game window, in fact, it always returns the coordinates at the center, ie: if I have res=1280x1024, and the game is fullscreen, both of my functions give me 640x512, all the time.

My theory is that the game has a mouse movement system like an fps.

The mouse is trapped at the center of the screen.

There is a software cursor. When the mouse is moved, it gets sent back to the center and the software cursor is updated with the amount the mouse moved.

If this is the case, how can I get the position of the software cursor?

Edited by zeropoint
  • Moderators
Posted

Continuous bumps in one thread are not only annoying, but are also rude to those others that have their questions waiting to be answered.

I can appreciate the fact you waited at least 24 hours in between bumps, but I personally think that's enough. If you don't get a reply to your post that works for you, then the thread must die until someone finds it and feels they can contribute an answer that will help you.

If you want the coordinates of the Client of the window, then use:

Opt ("MouseCoordMode", 2)

In addition, it sounds to me that they have blocked the API calls to find the mouse position, some type of Game guard or something... You won't find many ways around those without hacking the game itself.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted (edited)

Hi! i want to help but i get confused :)

Your first intention is to get mouse position, right? so you use:

$pos = MouseGetPos()

MsgBox(0,"Your mouse pointer coordinate is:", $pos[0]&"x"&$pos[1])

the MsgBox will return a coordinate like 640x512, that solves your first problem.

Now your second problem is to make mouse move to a certain coordinate, right?

lets say your given coordinate is: 700x600

$x = 700

$y = 600

MouseMove($x, $y)

$pos = MouseGetPos()

MsgBox(0,"Your mouse pointer coordinate is:", $pos[0]&"x"&$pos[1])

The mouse will move to coodinate 700x600 and MsgBox return same coodinate.

Im also in making bots using AutoIt and i already made some and posted it in my blogsite.

Edited by spaghett1
Posted

I don't know about this, but my experience with using Mouse* functions with games(asuming this is a 3D game here), is that the mouse pointer is always locked to the center of the screen.

Though using MouseMove, or similar move-related action on the mouse will still work(MouseGetPos will still return that the mouse pointer is in the center of the screen though).

That's my experience of the problem with mouse functions and 3D games atleast....

  • 4 years later...
Posted

Sorry for bringing this from the dead, but the answer to this is:

Run the game in a windowed mode, in fullscreen mode mouse coords are not working. Never did, never will ;)

  • 8 months later...
Posted

This was first posted a long long time ago, but I think I just found the solution, and this could help some other noobies out aswell.

I'm not sure why this works, but it worked for me, all you have to do is put the Global $MousePos = MouseGetPos() inside the Function:

HotKeySet("{NUMPAD2}", "MouseCoords")

Func MouseCoords()

Global $MousePos = MouseGetPos()

MsgBox(0, "Mouse Coords", "Your coords are: " & $MousePos[0] & " , " & $MousePos[1])

EndFunc

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...