Jump to content
Sign in to follow this  
eleria

Real-time (or almost) MouseGetPos?

Recommended Posts

eleria

Hi guys I would like to know the fastest way to use MouseGetPos everytime the user moves a bit

(I know WM_MouseMove the problem is that it just sucks CPU cycles like no tomorrow and sleeps make the whole script hog at times... )

You know in drawing softwares they display Mouse X Y coords without using any ressource... is it possible with AU3 ?

Share this post


Link to post
Share on other sites
rawrr

HotKeySet("{INS}","Pos")

Func Pos()
    $pos = MouseGetPos()
    MsgBox(0, "Mouse x,y:", $pos[0] & "," & $pos[1])
EndFunc

While 1
WEnd

For some reason I'm blanking out and can't think of how to make it work without the While 1 but this works fine..

Btw, just press Insert and a message box will come up telling you your mouse's cords..

Edited by rawrr

Share this post


Link to post
Share on other sites
ProgAndy

I think, you mean this way:

A sleep of 10ms is so less you can't feel it, when you use the Script.

$savepos = MouseGetPos()
$SaveColor = PixelGetColor($savepos[0],$savepos[1])
While 1
    Sleep(10)
    $pos = MouseGetPos()
    $color = PixelGetColor($pos[0],$pos[1])
    If $savepos[0] <> $pos[0] Or $savepos[1] <> $pos[1] Or $color <> $SaveColor Then 
        ToolTip("X: " & $pos[0] & @CRLF & "Y: " & $pos[1] & @CRLF & "Color: 0x" &Hex($color))
        $savepos = $pos
        $SaveColor = $color
    EndIf
WEnd
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
LongBowNZ

This works for me but I haven't tried the other ones which are probably better

#include <GUIConstantsEx.au3>
AutoItSetOption("MouseCoordMode", 2)

GUICreate("TEST", 500, 500, -1, -1)
$label = GUICtrlCreateLabel("", 50, 50, 100, 20)
GUISetState()

AdlibEnable("MousePos", 10)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            AdlibDisable()
            Exit
    EndSelect
WEnd

Func MousePos()
    $pos = MouseGetPos()
    GUICtrlSetData($label, $pos[0] & "," & $pos[1])
EndFunc
Edited by LongBowNZ

Share this post


Link to post
Share on other sites
eleria

Well I think the best conditional statement is an addition of both x and y

Switch ($savepos[0] + $savepos[1]) <> ($pos[0] + $pos[1]))

Edited by eleria

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×