Jump to content

MouseMove issue within dll callback ...


Go to solution Solved by guinness,

Recommended Posts

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.

; ==========================================================================================
; = 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.

Edited by jaberwocky6669
Link to comment
Share on other sites

  • Solution

Don't do any processing in the 'Mouse_Proc'. For example you could create a GUI with a custom dummy control and then send a message (using GUICtrlSendToDummy) to that control for processing. Therefore you exit the 'Mouse_Proc' function as soon as possible. Just my 2 cents worth.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

guinness,

Good advice, as warned here...

The hook procedure should process a message in less time than the data entry specified in the LowLevelHooksTimeout value in the following registry key:

HKEY_CURRENT_USERControl PanelDesktop

The value is in milliseconds. If the hook procedure times out, the system passes the message to the next hook. However, on Windows 7 and later, the hook is silently removed without being called. There is no way for the application to know whether the hook is removed.

 

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

That's where I read about it. Also I did some testing ages ago and put a sleep of about 2000ms and the mouse become unresponsive. The whole dummy control idea was something I picked up from wraithdu.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...