Hospital Posted September 20, 2015 Share Posted September 20, 2015 (edited) How would you predict mouse position and direction? like let's say there would be a box that would try to go infront of your mouse in whatever direction it's moving.would this be difficult? many interesting ideas stem with this in mind. /editHey guys, I did some research and I've found something that does just this in another language.I have been looking over it for a little while now and I think I get it but I don't entirely enough to know how to transfer this to autoit.Autoit has so much potential, it has to be possible to do this right?http://jsfiddle.net/pfyruc14/5/ sorry to confuse Edited September 20, 2015 by Hospital Link to comment Share on other sites More sharing options...
Hospital Posted September 21, 2015 Author Share Posted September 21, 2015 bump Link to comment Share on other sites More sharing options...
JohnOne Posted September 21, 2015 Share Posted September 21, 2015 Have you tries anything, if so post it. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Hospital Posted September 21, 2015 Author Share Posted September 21, 2015 hey john, i'm glad you saw my thread. i'm sure you can help me.i have been looking at it for the past hours now and i still don't know how to move something like that to autoit Link to comment Share on other sites More sharing options...
water Posted September 21, 2015 Share Posted September 21, 2015 Please wait at least 24 hours before bumping a thread. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Hospital Posted September 22, 2015 Author Share Posted September 22, 2015 Bump Link to comment Share on other sites More sharing options...
water Posted September 22, 2015 Share Posted September 22, 2015 Check the mouse position using MouseGetPos in a loop and move the box accordingly. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Hospital Posted September 22, 2015 Author Share Posted September 22, 2015 (edited) Check the mouse position using MouseGetPos in a loop and move the box accordingly. that is not what im trying to do, though that is necessary as part the challenge is like i said before predictingthank you for your answer though water ; here is an example of what i mean brother --https://jsfiddle.net/pfyruc14/34/ Edited September 22, 2015 by Hospital Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 22, 2015 Moderators Share Posted September 22, 2015 Hospital,Does this help?expandcollapse popup#include <WindowsConstants.au3> HotKeySet("{ESC}", "_Exit") Global $aOldMousePos[2] = [@DesktopWidth / 2, @DesktopHeight / 2], $aMousePos[2], $iSensitivity = 3 AdlibRegister("_Mouse_Pos") $hGUI = GUICreate("", 5, 5, -1, -1, $WS_POPUP) GUISetBkColor(0xFF0000) GUISetState() While 1 Sleep(10) WEnd Func _Mouse_Pos() $aMousePos = MouseGetPos() $iXdiff = $aMousePos[0] - $aOldMousePos[0] $iYdiff = $aMousePos[1] - $aOldMousePos[1] WinMove($hGUI, "", $aMousePos[0] + ($iSensitivity * $iXdiff), $aMousePos[1] + ($iSensitivity * $iYdiff)) $aOldMousePos = $aMousePos EndFunc Func _Exit() Exit EndFuncM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
czardas Posted September 22, 2015 Share Posted September 22, 2015 And the purpose is? operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Hospital Posted September 22, 2015 Author Share Posted September 22, 2015 (edited) Hospital,Does this help?expandcollapse popup#include <WindowsConstants.au3> HotKeySet("{ESC}", "_Exit") Global $aOldMousePos[2] = [@DesktopWidth / 2, @DesktopHeight / 2], $aMousePos[2], $iSensitivity = 3 AdlibRegister("_Mouse_Pos") $hGUI = GUICreate("", 5, 5, -1, -1, $WS_POPUP) GUISetBkColor(0xFF0000) GUISetState() While 1 Sleep(10) WEnd Func _Mouse_Pos() $aMousePos = MouseGetPos() $iXdiff = $aMousePos[0] - $aOldMousePos[0] $iYdiff = $aMousePos[1] - $aOldMousePos[1] WinMove($hGUI, "", $aMousePos[0] + ($iSensitivity * $iXdiff), $aMousePos[1] + ($iSensitivity * $iYdiff)) $aOldMousePos = $aMousePos EndFunc Func _Exit() Exit EndFuncM23So cool!! I'm definitely gonna be looking at this and coming up with all kinds of ideas.why does the red box act so jerky as compared to the example in js though? whats the difference?when I was looking over the code, i saw that somehow it stays a certain distance from the mouse cursor or the point thank you guys/edit i think the reason is because that js one must be a complex verison of the example? i wonder whats so different Edited September 22, 2015 by Hospital Link to comment Share on other sites More sharing options...
Hospital Posted September 22, 2015 Author Share Posted September 22, 2015 (edited) By the way thank you again so much, this is really interesting.How do you just make this stuff like this lol /edit this sensitivity thing is pretty interesting Edited September 22, 2015 by Hospital Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 22, 2015 Moderators Share Posted September 22, 2015 Hospital,I have no idea why it behaves "so jerky" compared to the js example as I did not look at the js code before writing my script - it is "all my own work". You could try reducing the Adlib time (it currently uses the default 250ms interval) which could well make the movement smoother.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Hospital Posted September 22, 2015 Author Share Posted September 22, 2015 Hospital,I have no idea why it behaves "so jerky" compared to the js example as I did not look at the js code before writing my script - it is "all my own work". You could try reducing the Adlib time (it currently uses the default 250ms interval) which could well make the movement smoother.M23like the red dot , could it be a certain distance from the mouse? Link to comment Share on other sites More sharing options...
JohnOne Posted September 22, 2015 Share Posted September 22, 2015 Expanding on M23 example, here is a little more control for fine tuning...expandcollapse popupHotKeySet("{ESC}", "_Exit") Global $aOldMousePos[2] = [@DesktopWidth / 2, @DesktopHeight / 2], $aMousePos[2], $iSensitivity = 3 Global $iFrequency = 10, $iTolerance = 5 AdlibRegister("_Mouse_Pos", $iFrequency) $hGUI = GUICreate("", 5, 5, -1, -1, $WS_POPUP) GUISetBkColor(0xFF0000) GUISetState() While 1 Sleep(10) WEnd Func _Mouse_Pos() $aMousePos = MouseGetPos() If _ToleranceExceeded($aMousePos, $aOldMousePos) Then $iXdiff = $aMousePos[0] - $aOldMousePos[0] $iYdiff = $aMousePos[1] - $aOldMousePos[1] WinMove($hGUI, "", $aMousePos[0] + ($iSensitivity * $iXdiff), $aMousePos[1] + ($iSensitivity * $iYdiff)) $aOldMousePos = $aMousePos EndIf EndFunc ;==>_Mouse_Pos Func _ToleranceExceeded(ByRef $m1, ByRef $m2) If Abs($m1[0] - $m2[0]) >= $iTolerance Or Abs($m1[1] - $m2[1]) >= $iTolerance Then Return True EndIf Return False EndFunc ;==>_ToleranceExceeded Func _Exit() Exit EndFunc ;==>_Exit AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 22, 2015 Moderators Share Posted September 22, 2015 Hospital,And if you want the dot at a fixed distance from the mouse, you can do something like this:expandcollapse popup#include <WindowsConstants.au3> HotKeySet("{ESC}", "_Exit") Global $aOldMousePos[2] = [@DesktopWidth / 2, @DesktopHeight / 2], $aMousePos[2], $iOffsetDist = 20 AdlibRegister("_Mouse_Pos", 50) $hGUI = GUICreate("", 5, 5, -1, -1, $WS_POPUP) GUISetBkColor(0xFF0000) GUISetState() While 1 Sleep(10) WEnd Func _Mouse_Pos() $aMousePos = MouseGetPos() $iXdiff = $aMousePos[0] - $aOldMousePos[0] Select Case $iXdiff = 0 $iXOffset = 0 Case $iXdiff > 0 $iXOffset = $iOffsetDist Case $iXdiff < 0 $iXOffset = -$iOffsetDist EndSelect $iYdiff = $aMousePos[1] - $aOldMousePos[1] Select Case $iYdiff = 0 $iYOffset = 0 Case $iYdiff > 0 $iYOffset = $iOffsetDist Case $iYdiff < 0 $iYOffset = -$iOffsetDist EndSelect WinMove($hGUI, "", $aMousePos[0] + $iXOffset, $aMousePos[1] + $iYOffset) $aOldMousePos = $aMousePos EndFunc Func _Exit() Exit EndFuncI increased the frequency of the Adlib call and it is now much smoother.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted September 22, 2015 Share Posted September 22, 2015 Been trying to improve this a bit but it's doing my head in now.In the below code, the diagonal movement is great, but the horizontal and vertical are lousy.If you uncomment the block then the vertical and horizontal are great but the diagonal is lousy.expandcollapse popup#include <WindowsConstants.au3> HotKeySet("{ESC}", "_Exit") Global $aOldMousePos[2] = [@DesktopWidth / 2, @DesktopHeight / 2], $aMousePos[2], $iOffsetDist = 100 Global $iFrequency = 10, $iTolerance = 15 AdlibRegister("_Mouse_Pos", $iFrequency) $hGUI = GUICreate("", 5, 5, -1, -1, $WS_POPUP, $WS_EX_TOPMOST) GUISetBkColor(0xFF0000) GUISetState() While 1 Sleep(10) WEnd Func _Mouse_Pos() Local $iXOffset Local $iYOffset ;Local Static $aOldMousePos = MouseGetPos() Local $iXdiff Local $iYdiff $aMousePos = MouseGetPos() $xTolExceeded = _XToleranceExceeded($aMousePos, $aOldMousePos) $yTolExceeded = _YToleranceExceeded($aMousePos, $aOldMousePos) If $xTolExceeded Then $iXdiff = $aMousePos[0] - $aOldMousePos[0] Select Case $iXdiff = 0 $iXOffset = 0 Case $iXdiff > 0 $iXOffset = $iOffsetDist Case $iXdiff < 0 $iXOffset = -$iOffsetDist EndSelect EndIf If $yTolExceeded Then $iYdiff = $aMousePos[1] - $aOldMousePos[1] Select Case $iYdiff = 0 $iYOffset = 0 Case $iYdiff > 0 $iYOffset = $iOffsetDist Case $iYdiff < 0 $iYOffset = -$iOffsetDist EndSelect EndIf If $xTolExceeded And $yTolExceeded Then WinMove($hGUI, "", $aMousePos[0] + $iXOffset, $aMousePos[1] + $iYOffset) $aOldMousePos = $aMousePos Return EndIf #cs If $xTolExceeded Then WinMove($hGUI, "", $aOldMousePos[0] + $iXOffset, $aMousePos[1] + $iYOffset) $aOldMousePos = $aMousePos Return EndIf If $yTolExceeded Then WinMove($hGUI, "", $aMousePos[0] + $iXOffset, $aOldMousePos[1] + $iYOffset) $aOldMousePos = $aMousePos Return EndIf #ce EndFunc ;==>_Mouse_Pos Func _XToleranceExceeded(ByRef $m1, ByRef $m2) If (Abs($m1[0] - $m2[0]) >= $iTolerance) Then Return True EndIf Return False EndFunc ;==>_XToleranceExceeded Func _YToleranceExceeded(ByRef $m1, ByRef $m2) If (Abs($m1[1] - $m2[1]) >= $iTolerance) Then Return True EndIf Return False EndFunc ;==>_YToleranceExceeded Func _ToleranceExceeded(ByRef $m1, ByRef $m2) If (Abs($m1[0] - $m2[0]) >= $iTolerance) Or (Abs($m1[1] - $m2[1]) >= $iTolerance) Then Return True EndIf Return False EndFunc ;==>_ToleranceExceeded Func _Exit() Exit EndFunc ;==>_Exit AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Malkey Posted September 22, 2015 Share Posted September 22, 2015 (edited) Here is an example using a line to indicate mouse direction.expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> Opt("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client HotKeySet("{ESC}", "Terminate") Global $hDC, $hPen, $o_Orig $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) $hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0xFF) $o_Orig = _WinAPI_SelectObject($hDC, $hPen) Local $exit = 1 While $exit Sleep(10) _MouseDirection() WEnd ; clear resources _WinAPI_SelectObject($hDC, $o_Orig) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) Func _MouseDirection() Local Static $iOldX = 0, $iOldY = 0 Local $Pi = 4 * ATan(1), $iLength, $aPos $aPos = MouseGetPos() While (Abs($iOldX - $aPos[0]) > 0) Or (Abs($iOldY - $aPos[1]) > 0) $aPos = MouseGetPos() $iGradient = ATan(($aPos[1] - $iOldY) / ($aPos[0] - $iOldX)) $iLength = Sqrt(($aPos[1] - $iOldY) ^ 2 + ($aPos[0] - $iOldX) ^ 2); <--- Length varies with speed of mouse movement. ; Or ;$iLength = 40 ; <--- Direction line has fixed length. If $iLength < 40 Then $iLength = 40 ; <--- Direction line has minimum length. If (($aPos[0] - $iOldX) < 0) And (Abs($aPos[1] - $iOldY) < 2) Then ; X neg, Y = 0 _WinAPI_DrawLine($hDC, $aPos[0], $aPos[1], $aPos[0] - $iLength, $aPos[1]) ElseIf (Abs($aPos[0] - $iOldX) < 2) And (($aPos[1] - $iOldY) < 0) Then ; X= 0, Y neg _WinAPI_DrawLine($hDC, $aPos[0], $aPos[1], $aPos[0], $aPos[1] - $iLength) ElseIf (Abs($aPos[0] - $iOldX) < 2) And (($aPos[1] - $iOldY) > 0) Then ; X= 0, Y pos _WinAPI_DrawLine($hDC, $aPos[0], $aPos[1], $aPos[0], $aPos[1] + $iLength) ElseIf (($aPos[0] - $iOldX) < 0) And (($aPos[1] - $iOldY) > 0) Then ; X neg, Y pos _WinAPI_DrawLine($hDC, $aPos[0], $aPos[1], $aPos[0] - Cos($iGradient) * $iLength, $aPos[1] - Sin($iGradient) * $iLength) ElseIf (($aPos[0] - $iOldX) < 0) And (($aPos[1] - $iOldY) < 0) Then ; X neg, Y neg _WinAPI_DrawLine($hDC, $aPos[0], $aPos[1], $aPos[0] - Cos($iGradient) * $iLength, $aPos[1] - Sin($iGradient) * $iLength) Else _WinAPI_DrawLine($hDC, $aPos[0], $aPos[1], $aPos[0] + Cos($iGradient) * $iLength, $aPos[1] + Sin($iGradient) * $iLength) EndIf If $iOldX <> $aPos[0] Or $iOldY <> $aPos[1] Then $iOldX = $aPos[0] $iOldY = $aPos[1] EndIf Sleep(50) _WinAPI_RedrawWindow("", 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN) WEnd Return EndFunc ;==>_MouseDirection Func Terminate() $exit = 0 EndFunc ;==>Terminate Edited September 22, 2015 by Malkey Removed "(($aPos[0] - $iOldX) > 0) And (($aPos[1] - $iOldY) > 0)" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 22, 2015 Moderators Share Posted September 22, 2015 Malkey,I am afraid that does not work for me. I have to correct the Else case for what looks like an extraneous line and then I get a single red line which vanishes as soon as I move the mouse.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted September 22, 2015 Share Posted September 22, 2015 I figured that was important s...ConsoleWrite((($aPos[0] - $iOldX) > 0) And (($aPos[1] - $iOldY) > 0)) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now