MDCT Posted December 7, 2011 Posted December 7, 2011 Hello again, I have a problem with this only when my mouse pointer is on the edges of the screen. When the cursor is on left edge of the screen, the Xpos sometimes returns negative (-1, -2). When on the top edge the Ypos sometimes returns negative (-1, -2) When on right edge, Xpos sometimes it returns bigger than my screen width (mine is 1024, sometimes it returns 1025). And when on bottom edge, sometimes it return value higher than my screen height. I believe I have tried all the examples on the forum but, they all have the same problem. Does this problem happen only on my computer? Below is the example script. expandcollapse popupHotKeySet ( "{Esc}" , "OnAutoItExit") Global Const $WH_MOUSE_LL=14 Global Const $tagPOINT="int X;int Y" Global $MposX Global $MposY $hKey_Proc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr") $hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0) $hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0) While 1 Sleep(128) ConsoleWrite($MposX&" "&$MposY&@CRLF) WEnd Func _Mouse_Proc($nCode, $wParam, $lParam) Local $info If $nCode < 0 Then $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _ "int", $nCode, "ptr", $wParam, "ptr", $lParam) Return $ret[0] EndIf $info = DllStructCreate($tagPOINT, $lParam) $MposX = DllStructGetData($info, 1) $MposY = DllStructGetData($info, 2) $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _ "int", $nCode, "ptr", $wParam, "ptr", $lParam) Return $ret[0] EndFunc ;==>_Mouse_Proc Func OnAutoItExit() DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0]) $hM_Hook[0] = 0 DllCallbackFree($hKey_Proc) $hKey_Proc = 0 Exit EndFunc Can someone help me fix this problem? Thank you very much.
KaFu Posted December 7, 2011 Posted December 7, 2011 This happens because the actual virtual desktop is much larger than the visible desktop. Here's a work-around using buffered positions. expandcollapse popupHotKeySet("{Esc}", "OnAutoItExit") Global Const $WH_MOUSE_LL = 14 Global Const $tagPOINT = "int X;int Y" Global $MposX Global $MposY $hKey_Proc = DllCallbackRegister("_Mouse_Proc", "int", "int;ptr;ptr") $hM_Module = DllCall("kernel32.dll", "hwnd", "GetModuleHandle", "ptr", 0) $hM_Hook = DllCall("user32.dll", "hwnd", "SetWindowsHookEx", "int", $WH_MOUSE_LL, "ptr", DllCallbackGetPtr($hKey_Proc), "hwnd", $hM_Module[0], "dword", 0) Global $MposX_Buffer = MouseGetPos(0), $MposY_Buffer = MouseGetPos(1) While 1 Sleep(250) ConsoleWrite($MposX_Buffer & " " & $MposY_Buffer & @CRLF) WEnd Func _Mouse_Proc($nCode, $wParam, $lParam) Local $info If $nCode < 0 Then $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _ "int", $nCode, "ptr", $wParam, "ptr", $lParam) Return $ret[0] EndIf $info = DllStructCreate($tagPOINT, $lParam) Local $MposX = DllStructGetData($info, 1) Local $MposY = DllStructGetData($info, 2) If $MposX > @DesktopWidth Then $MposX = @DesktopWidth If $MposX < 0 Then $MposX = 0 If $MposY > @DesktopHeight Then $MposY = @DesktopHeight If $MposY < 0 Then $MposY = 0 If $MposX <> $MposX_Buffer Or $MposY <> $MposY_Buffer Then $MposX_Buffer = $MposX $MposY_Buffer = $MposY ; ConsoleWrite($MposX_Buffer & "x" & $MposY_Buffer & @CRLF) EndIf $ret = DllCall("user32.dll", "long", "CallNextHookEx", "hwnd", $hM_Hook[0], _ "int", $nCode, "ptr", $wParam, "ptr", $lParam) Return $ret[0] EndFunc ;==>_Mouse_Proc Func OnAutoItExit() DllCall("user32.dll", "int", "UnhookWindowsHookEx", "hwnd", $hM_Hook[0]) $hM_Hook[0] = 0 DllCallbackFree($hKey_Proc) $hKey_Proc = 0 Exit EndFunc ;==>OnAutoItExit OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
MDCT Posted December 7, 2011 Author Posted December 7, 2011 Owww, bro KaFu. Thanks for the help. It works, but is there any workout without expressions (Ifs) like this?Really appreciate it, but it's not what I was looking for.
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