Given a specific XY coordinate, this snippet returns the handle to the monitor the coordinate appears on... or 0 if it is off all screens. Particularly useful in multiple monitor setups where monitors have different resolutions or are offset vertically or horizontally (in which case, there are areas of the virtual desktop that are off all screens).
You could also use it to return the handle of the monitor where a window is placed, or where the mouse was clicked, or other similar applications.
#include <WinAPIGdi.au3> ;for _WinOnMonitor() Func _WinOnMonitor($iXPos, $iYPos) Local $aMonitors = _WinAPI_EnumDisplayMonitors() If IsArray($aMonitors) Then ReDim $aMonitors[$aMonitors + 1] For $ix = 1 To $aMonitors $aPos = _WinAPI_GetPosFromRect($aMonitors[$ix]) For $j = 0 To 3 $aMonitors[$ix][$j + 1] = $aPos[$j] Next Next EndIf For $ixMonitor = 1 to $aMonitors ; Step through array of monitors If $iXPos > $aMonitors[$ixMonitor] And $iXPos < $aMonitors[$ixMonitor] + $aMonitors[$ixMonitor] Then If $iYPos > $aMonitors[$ixMonitor] And $iYPos < $aMonitors[$ixMonitor] + $aMonitors[$ixMonitor] Then Return $aMonitors[$ixMonitor] ; return handle to monitor coordinate is on EndIf EndIf Next Return 0 ;Return 0 if coordinate is on none of the monitors EndFunc ;==> _WinOnMonitor
This script is intended to allow the user to move their mouse to the edge of their screen and have the mouse appear to the opposite end.
When the user drags the mouse to the edge of a monitor there is a 300 millisecond delay before the mouse will wrap. This will give the user some time to change their mind and give some time for the taskbar to open if the user has it set to autohide.
When the user drags a window or selection rectangle to the edge of a monitor the user will have 700 milliseconds to take advantage of the Windows 7 Snap feature. If the user has not moved the mouse from the edge within that time then the window will move to the opposite edge.
When the user holds down the mouse wheel the wrap effect is disabled.
Tested on Windows 7 x64 with two monitors placed horizontally.
MouseWrap.zip - Source works on latest AutoIt beta. Includes an exe.