Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Beta Test My Latest Script? Please?

$
0
0

I'm working on a script for two monitors (currently) 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.

 

Care to try it out for me?

 

Included is the script from MouseSpotter which captures mouse and keyboard events.  However, I have modified it to handle only mouse drag events.  If you don't feel like going through all of that, I have included the exe of the mouse wrap script too.

 

Download the EXE!

 

Be sure to head to UDF Input Event Capture - Mouse & Keyboard  to grab the necessary dll (not necessary if using my exe).

AutoIt Code         
#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d ; Highly modified by yours truly to handle only mouse drag events. #include-once #region - Module #region -- Private Variables     ; Class Names     Global $_InputEvent_CLASS_MOUSE = "mouse"     Global $_InputEvent_CLASS_DRAG  = "drag"     ; Event     Global  $_InputEvent_EventClass      = ''     Global  $_InputEvent_EventName       = ''     Global  $_InputEvent_EventNumber     = 0     Global  $_InputEvent_EventNumberLast = 0     ; Mouse     Global  $_InputEvent_MouseEventName = ''     Global  $_InputEvent_MouseObject    = ''     ; Dragging     Global  $_InputEvent_DragObject = ''     ; Prior Event Fields     Global $_InputEvent_MouseLastObject = ''     Global $_InputEvent_MouseDownObject = ''     ; DLL Handles     Global Const $_InputEvent_InputEvent_DLL = DllOpen("InputEvent.dll")     If $_InputEvent_InputEvent_DLL =-1 Then         MsgBox(0, "InputEvent", "Unable to open InputEvent.dll" & @crlf & "Program will terminate.")         Exit     EndIf     Global Const $_InputEvent_USER32_DLL = DllOpen("user32.dll")     Global $_InputEvent_PollInterval = 10 #endregion -- Private Variables #region -- Public Functions ; #PUBLIC# ;================================================================================== ; Name...........:  _InputEvent_SetPollInterval ; Description ...:  Sets the delay between an event being captured and it being actioned ;                             Note: setting this too low results in events being missed / reported in the wrong order ; Syntax.........:  _InputEvent_SetPollInterval($millisecs) ; Parameters ....:  $millisecs | milliseconds delay ; ============================================================================================ Func _InputEvent_SetPollInterval(Const $millisecs)     $_InputEvent_PollInterval = $millisecs EndFunc ; #PUBLIC# ;================================================================================ ; Name...........:  _InputEvent_StartUp ; Description ...:  Starts the capture of events. ; Syntax.........:  _InputEvent_StartUp() ; Return values .:  Boolean ;                                           | True  = Success ;                                           | False = DllCall failed and @error is set accordingly. ; ============================================================================================ Func _InputEvent_StartUp()     Local Const $_InputEvent_MouseFuncBack    = DllCallBackRegister("__InputEvent_MouseEvent", "int", "str;str;long;long;int")     Local Const $_InputEvent_MouseFuncBackPtr = DllCallBackGetPtr($_InputEvent_MouseFuncBack)     DllCall($_InputEvent_InputEvent_DLL, "int:cdecl", "CaptureMouse", "ptr", $_InputEvent_MouseFuncBackPtr)     Switch @error         Case 0             Return True         Case Else             Return SetError(@error, 0, False)     EndSwitch EndFunc #endregion -- Public Functions #region -- Private Functions ; #PRIVATE ;================================================================================== ; Name...........:  __InputEvent_ClearEventVariables ; Description ...:  Clears the working variables ; ============================================================================================ Func __InputEvent_ClearEventVariables()     ; Event     $_InputEvent_EventClass = ''     $_InputEvent_EventName  = ''     ; Mouse     $_InputEvent_MouseEventName = ''     $_InputEvent_MouseObject    = '' EndFunc ; #PRIVATE ;================================================================================== ; Name...........:  _InputEvent_InvokeEvent ; Description ...:  Invokes the external user defined event handlers ; ============================================================================================ Func __InputEvent_InvokeEvent(Const ByRef $event_object)     If $_InputEvent_EventNumber = $_InputEvent_EventNumberLast Then Return     $_InputEvent_EventNumberLast = $_InputEvent_EventNumber     Local Const $invoke_function_name = "_InputEvent_" & $_InputEvent_EventName     Switch $_InputEvent_EventClass         Case $_InputEvent_CLASS_DRAG             Switch $_InputEvent_EventName                 Case "dragstart", "dragend"                     Call($invoke_function_name, $event_object)             EndSwitch     EndSwitch EndFunc ; #PRIVATE ;================================================================================== ; Name...........:  __InputEvent_MouseEvent ; Description ...:  Invoked by the InputEvent.dll when a mouse event occurs ; ============================================================================================ Func __InputEvent_MouseEvent($event_name, $mouse_button, $x, $y, $time)     $_InputEvent_MouseEventName = $event_name     $_InputEvent_MouseObject      = __InputEvent_WindowFromPoint($x, $y)     __InputEvent_MouseHandler() EndFunc ; #PRIVATE ;================================================================================== ; Name...........:  __InputEvent_MouseHandler ; Description ...:  Invoked by the_InputEvent_MouseEvent when a mouse event occurs to map the event ; ============================================================================================ Func __InputEvent_MouseHandler()     If Not $_InputEvent_MouseLastObject Then $_InputEvent_MouseLastObject = $_InputEvent_MouseObject     Switch $_InputEvent_MouseEventName         Case "Down"             ; MouseDown             $_InputEvent_EventNumber         += 1             $_InputEvent_MouseDownObject =  $_InputEvent_MouseObject             $_InputEvent_EventClass          =  $_InputEvent_CLASS_MOUSE             $_InputEvent_EventName           =  "MouseDown"             __InputEvent_InvokeEvent($_InputEvent_MouseDownObject)         Case "Move"             If $_InputEvent_DragObject = 0 Then                 If $_InputEvent_MouseDownObject <> 0 Then                     ; DragStart                     $_InputEvent_EventNumber += 1                     $_InputEvent_DragObject  =  $_InputEvent_MouseDownObject                     $_InputEvent_EventClass  =  $_InputEvent_CLASS_DRAG                     $_InputEvent_EventName   =  "DragStart"                     __InputEvent_InvokeEvent($_InputEvent_DragObject)                     $_InputEvent_MouseDownObject    = 0                 EndIf             EndIf             If $_InputEvent_DragObject <> 0 Then                 ; DragMove                 $_InputEvent_EventNumber    += 1                 $_InputEvent_EventClass     = $_InputEvent_CLASS_DRAG                 $_InputEvent_EventName  = "DragMove"                 __InputEvent_InvokeEvent($_InputEvent_DragObject)             EndIf         Case "Up"             ; we are dragging Then send DragEnd > MouseUp             If $_InputEvent_DragObject <> 0 Then                 ; ... yes it is                 ; DragEnd                 $_InputEvent_EventNumber    += 1                 $_InputEvent_EventClass     = $_InputEvent_CLASS_DRAG                 $_InputEvent_EventName      = "DragEnd"                 __InputEvent_InvokeEvent($_InputEvent_DragObject)                 $_InputEvent_DragObject = 0             EndIf             $_InputEvent_MouseDownObject = 0     EndSwitch     __InputEvent_ClearEventVariables() EndFunc ; #PRIVATE ;================================================================================== ; Name...........:  __InputEvent_WindowFromPoint ; Description ...:  Gets a window handle for the windown under a point on the screen ; Return values .:  Handle to a window. ; ============================================================================================ Func __InputEvent_WindowFromPoint(Const $x, Const $y)     Return DLLCall($_InputEvent_USER32_DLL, "hwnd", "WindowFromPoint", "int", $x, "int", $y)[0] EndFunc #endregion -- Private Functions #endregion - Module

Here is the mouse wrap script:

AutoIt Code         
; ====================================================================================================================== ; = Credits: ; =   DrLarch:      http://www.autoitscript.com/forum/topic/131618-detect-monitor-maximum-native-resolution/?p=1071159 ; =        MouseSpotter: http://www.autoitscript.com/forum/topic/149971-udf-input-event-capture-mouse-keyboard/?p=1070143 ; ====================================================================================================================== #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 "InputEvent.au3" _InputEvent_StartUp() Global $paused = False main() Func main()     Local Const $desktop_width = _WinAPI_GetSystemMetrics(78)     Local Const $monitor2_height = get_monitor2_height()     Local $mouse_x = ''     Local $mouse_y = ''     Do         Switch Not $paused             Case True                 $mouse_x = MouseGetPos(0)                 $mouse_y = MouseGetPos(1)                 Select                     Case $mouse_x <= @DesktopWidth                         Select                             Case $mouse_y = (@DesktopHeight - 1)                                 MouseMove($mouse_x, 1, 0)                                 ContinueLoop                         EndSelect                     Case $mouse_x > @DesktopWidth                         Select                             Case $mouse_y = ($monitor2_height - 1)                                 MouseMove($mouse_x, 1, 0)                                 ContinueLoop                         EndSelect                 EndSelect                 Select                     Case $mouse_x = 0                         MouseMove(($desktop_width - 1), $mouse_y, 0)                     Case $mouse_x = ($desktop_width - 1)                         MouseMove(1, $mouse_y, 0)                     Case $mouse_y = 0                         MouseMove($mouse_x, (@DesktopHeight - 1), 0)                 EndSelect         EndSwitch         Sleep(15)     Until False EndFunc Func _InputEvent_DragStart(Const ByRef $handle)     $paused = Not $paused EndFunc Func _InputEvent_DragEnd(Const ByRef $handle)     $paused = Not $paused EndFunc ; taken from: http://www.autoitscript.com/forum/topic/131618-detect-monitor-maximum-native-resolution/?p=1071159 Func get_monitor2_height()     Local Const $display_device = DllStructCreate("dword; char[32]; char[128]; dword; char[128]; char[128]")     DllStructSetData($display_device, 1, DllStructGetSize($display_device)) ;~     Local Const $display_monitor_amount = _WinAPI_GetSystemMetrics(80) ;~     Local Const $enum_display_devices = DllCall("User32.dll", "bool", "EnumDisplayDevices", "ptr", 0, "dword", ($display_monitor_amount - 1), "ptr", DllStructGetPtr($display_device), "dword", 1)[0]     Local Const $enum_display_devices = DllCall("User32.dll", "bool", "EnumDisplayDevices", "ptr", 0, "dword", 1, "ptr", DllStructGetPtr($display_device), "dword", 1)[0]     Local Const $device_name = DllStructGetData($display_device, 2)     Local Const $tag_DEVMODE = "char dmDeviceName[32];ushort dmSpecVersion;ushort dmDriverVersion;short dmSize;"                            & _                                                          "ushort dmDriverExtra;dword dmFields; long x;long y; dword dmDisplayOrientation;dword dmDisplayFixedOutput;" & _                                                          "short dmColor;short dmDuplex;short dmYResolution;short dmTTOption;short dmCollate;"                         & _                                                          "byte dmFormName[32];ushort LogPixels;dword dmBitsPerPel;int dmPelsWidth;dword dmPelsHeight;"                & _                                                          "dword dmDisplayFlags;dword dmDisplayFrequency"     Local Const $DEVMODE = DllStructCreate($tag_DEVMODE)     DllStructSetData($DEVMODE, "dmSize", DllStructGetSize($DEVMODE))     DllCall("User32.dll", "bool", "EnumDisplaySettings", "str", $device_name, "dword", -1, "ptr", DllStructGetPtr($DEVMODE))     Return DllStructGetData($DEVMODE, "dmPelsHeight") EndFunc

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>