Search the Community
Showing results for tags 'mousemove not working always'.
-
This one has me baffled. I can't seem to get MouseMove to work properly with scaling in some windows. Run this program and use the arrow keys to move the mouse Up, Down, Left, Right at native (100%) scaling and it works as expected. Now go to 125%, for example, and move Up, Down, Left, Right on the desktop and it works. Now open the MouseMove help window (cursor on MouseMove then F1). Move the mouse into the MouseMove help window and try Up, Down, Left, Right and the movements are diagonal! If you move, for example, right from desktop into the MouseMove window it goes from moving right to down and right (diagonal) as soon as the mouse hits the MouseMove help window. I'm stumped. How do I get MouseMove to work properly? Any hints appreciated. ; ;#AutoIt3Wrapper_run_debug_mode=Y ; use this to debug in console window <--- LOOK ;Trying to figure out how to scale properly for MouseMove - moving mouse in Up, Down, Left, Right moves diagonally on some windows if scale <> 1 (100%). ;Test on main monitor and use 1920x1080 then scale to 125% as simple example. ;To change display scale in Windows 10, right click on desktop "Display Settings" --> Scale and layout ;arrow keys on arrow keypad HotKeySet("{UP}", "__UpMouse") HotKeySet("{DOWN}", "__DownMouse") HotKeySet("{LEFT}", "__LeftMouse") HotKeySet("{RIGHT}", "__RightMouse") ;v2g - cutting out superfluous code to show issue, added scaling Opt("MouseCoordMode",1) ;1 = absolute screen coordinates (default) - use this because otherwise active window mucks it up $scale = _GetScale() MsgBox(0,"DEBUG", "$scale = " & $scale) While 1 ;watch the console - the mouse is not moving correctly Sleep(10) ;this works well and does not appear to use the CPU WEnd ;================= Functions ================== Func __UpMouse() Local $mousepos, $mouseposafter $mousepos = MouseGetPos() MouseMove($mousepos[0]+0, $mousepos[1]-1) $mouseposafter = MouseGetPos() ConsoleWrite("in __UpMouse()" & @CRLF & "Before UP (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After UP (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF) EndFunc Func __DownMouse() Local $mousepos, $mouseposafter $mousepos = MouseGetPos() MouseMove($mousepos[0]+0, $mousepos[1]+1) $mouseposafter = MouseGetPos() ConsoleWrite("in __DownMouse()" & @CRLF & "Before DOWN (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After DOWN (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF) EndFunc Func __LeftMouse() Local $mousepos, $mouseposafter $mousepos = MouseGetPos() MouseMove($mousepos[0]-1, $mousepos[1]+0) $mouseposafter = MouseGetPos() ConsoleWrite("in __LeftMouse()" & @CRLF & "Before LEFT (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After LEFT (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF) EndFunc Func __RightMouse() Local $mousepos, $mouseposafter $mousepos = MouseGetPos() MouseMove($mousepos[0]+1, $mousepos[1]+0) $mouseposafter = MouseGetPos() ConsoleWrite("in __RightMouse()" & @CRLF & "Before RIGHT (x,y) = " & $mousepos[0] & "," & $mousepos[1] & @CRLF & " After RIGHT (x,y) = " & $mouseposafter[0] & "," & $mouseposafter[1] & @CRLF & @CRLF) EndFunc Func _GetScale() ;returns a scale factor for PixelGetColor ;from: https://www.autoitscript.com/forum/topic/156251-mouse-coordinates/?tab=comments#comment-1130002 $tDEVMODE = DllStructCreate('byte[32];dword[10];byte[32];dword[6]') $pDEVMODE = DllStructGetPtr($tDEVMODE) $i = 0 while 1 $ret = DllCall('user32.dll', 'int', 'EnumDisplaySettings', 'ptr', 0, 'dword', $i, 'ptr', $pDEVMODE) if ($ret[0] = 0) then exitloop $width = DllStructGetData($tDEVMODE, 4, 2) ; native width $i += 1 wend $scale = $width / @DesktopWidth Return($scale) EndFunc
- 10 replies