I'm working on a script for one or more monitors that will wrap the mouse around the monitors and yet still allow you to drag windows to the edge of the monitor for the Windows 7 Snap feature.
I'm currently encountering a problem though. When I call "MouseMove" with a speed of zero from within my registered dll callback function "mouse_proc" the mouse refuses to move. When I set the speed to ten it will move but acts all weird. It gets caught in some sort of infinite loop I guess. Is it that "MouseMove" is some sort of blocking function? Care to take a look?
The script works properly when I move the call to "mouse_proc" to the Do Until loop.
AutoIt
; ========================================================================================== ; = MosueWrap - I intend to allow for mouse wrap action but still be able to utilize = ; = the Windows 7 Snap feature. Also, I intend for this to work on any number of monitors = ; ========================================================================================== ; ============================================================== ; = Credits: = ; = Guinness, Kylomas, Melba23, trancexx, WideBoyDixon, etc. = ; ============================================================== #AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d #include <Misc.au3> _Singleton(@ScriptName) #include <WinAPI.au3> #include <WindowsConstants.au3> Global Const $mouse_proc_callback = DllCallbackRegister("mouse_proc", "long", "int;wparam;lparam") Global Const $hook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($mouse_proc_callback), _WinAPI_GetModuleHandle(0)) OnAutoItExitRegister("cleanup") Do Sleep(10) Until False Func mouse_proc($code, $w_param, $l_param) Static $button_down = False Switch $code >= 0 Case True Switch $w_param Case $WM_LBUTTONDOWN, $WM_RBUTTONDOWN $button_down = True Case $WM_LBUTTONUP, $WM_RBUTTONUP $button_down = False Case $WM_MOUSEMOVE Switch Not $button_down Case True Local Const $x = MouseGetPos(0) Local Const $y = MouseGetPos(1) Local Const $virtual_desktop_width = _WinAPI_GetSystemMetrics($SM_CXVIRTUALSCREEN) Local Const $monitor_height = monitor_size_from_point($x, $y)[3] Select Case $x = 0 MouseMove($virtual_desktop_width - 1, $y, 0) Case $x = $virtual_desktop_width - 1 MouseMove(0, $y, 0) Case $y = 0 MouseMove($x, $monitor_height, 0) Case $y = $monitor_height - 1 MouseMove($x, 0, 0) EndSelect EndSwitch EndSwitch EndSwitch Return _WinAPI_CallNextHookEx($hook, $code, $w_param, $l_param) EndFunc ; ====================================================================== ; = WideBoyDixon = ; = http://www.autoitscript.com/forum/topic/94611-mouse-wrap/?p=679894 = ; ====================================================================== Func get_monitor_rect(Const ByRef $monitor_handle) Local Const $monitor_info = DllStructCreate("int; int[4]; int[4]; int; char[32]") DllStructSetData($monitor_info, 1, DllStructGetSize($monitor_info)) DllCall("User32.dll", "int", "GetMonitorInfo", "hwnd", $monitor_handle, "ptr", DllStructGetPtr($monitor_info)) Local $aRect[4] For $i = 1 To 4 $aRect[$i - 1] = DllStructGetData($monitor_info, 2, $i) Next $aRect[2] -= $aRect[0] $aRect[3] -= $aRect[1] Return $aRect EndFunc Func monitor_size_from_point(Const $x, Const $y) Local Const $monitor_handle = DllCall("User32.dll", "handle", "MonitorFromPoint", "int", $x, "int", $y, "int", 0)[0] Return get_monitor_rect($monitor_handle) EndFunc Func cleanup() _WinAPI_UnhookWindowsHookEx($hook) DllCallbackFree($mouse_proc_callback) EndFunc
Never mind the MouseGetPos for now. I think I can work on that after I clear this problem up.