#include #include #include #include #include #include #Region code on top Global $g_aSystemMetrics_MainButton_DownUp[4] = [0,0,0,0] ; [down value, up value, DClick timer, ON_MOUSEDCLICK() is running] ON_SETTINGCHANGE() Global $g_MousePos_last[3] = [0,0,TimerInit()] Global $g_WinActiveInfo[3] = [0,"",0] ; [handle, title, iIsScite] $g_WinActiveInfo[0] = WinActive("") $g_WinActiveInfo[1] = WinGetTitle($g_WinActiveInfo[0]) $g_WinActiveInfo[2] = _WinAPI_GetClassName ( $g_WinActiveInfo[0] ) Opt('TrayAutoPause', 0) ; Create GUI Global $g_SciTECmd, $My_Hwnd = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 160, 212, @DesktopWidth - 179, @DesktopHeight - 283, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_TOPMOST) ; To obtain the values of "UsagePage" and "Usage" members of this structure read HID Usage Tables documentation ; http://www.usb.org/developers/devclass_docs/HID1_11.pdf Global $___g_tRID = DllStructCreate($tagRAWINPUTDEVICE) DllStructSetData($___g_tRID, 'UsagePage', 0x01) ; Generic Desktop Controls DllStructSetData($___g_tRID, 'Usage', 0x02) ; Mouse DllStructSetData($___g_tRID, 'Flags', $RIDEV_INPUTSINK) DllStructSetData($___g_tRID, 'hTarget', $My_Hwnd) ; Register HID input to obtain row input from mice _WinAPI_RegisterRawInputDevices($___g_tRID) ; Register WM_INPUT message GUIRegisterMsg($WM_INPUT, 'WM_INPUT') GUIRegisterMsg($WM_SETTINGCHANGE, 'WM_SETTINGCHANGE') GUIRegisterMsg($WM_COPYDATA, "MY_WM_COPYDATA") GUISetState(@SW_SHOW) OnAutoItExitRegister("OnAutoItBye") #Region GetActiveWindow GUIRegisterMsg(RegisterWindowMessage("SHELLHOOK"), "HShellWndProc") ShellHookWindow($My_Hwnd, 1) Func RegisterWindowMessage($sText) Local $aRet = DllCall('user32.dll', 'int', 'RegisterWindowMessage', 'str', $sText) Return $aRet[0] EndFunc Func ShellHookWindow($hWnd, $bFlag) Local $sFunc = 'DeregisterShellHookWindow' If $bFlag Then $sFunc = 'RegisterShellHookWindow' Local $aRet = DllCall('user32.dll', 'int', $sFunc, 'hwnd', $hWnd) Return $aRet[0] EndFunc Func HShellWndProc($hWnd, $Msg, $wParam, $lParam) Switch $wParam ; https://www.autoitscript.com/forum/topic/56536-easy-shell-hooking-example/#comments Case $HSHELL_WINDOWACTIVATED, $HSHELL_WINDOWCREATED, $HSHELL_REDRAW, $HSHELL_RUDEAPPACTIVATED $g_WinActiveInfo[0] = WinActive("") $g_WinActiveInfo[1] = WinGetTitle($g_WinActiveInfo[0]) $g_WinActiveInfo[2] = _WinAPI_GetClassName($g_WinActiveInfo[0]) ;~ ConsoleWrite('+++ ' & $g_WinActiveInfo[0] & ' (' & $g_WinActiveInfo[1] & ')' & $g_WinActiveInfo[2] & @CRLF) EndSwitch EndFunc #EndRegion GetActiveWindow Do ; nothing for now. Just the GUI Until GUIGetMsg() = $GUI_EVENT_CLOSE #EndRegion code on top Func DoTheSciteStuff() ConsoleWrite('+ Func DoTheSciteStuff()' & @CRLF) Local $SciTE_hwnd = 0, $aList = WinList("DirectorExtension") ; Default to the first found but Loop through all available instances of the SciTEDirector interface to select the correct one by comparing the Filename. For $i = 1 To $aList[0][0] $CurrentFile = SendSciTE_GetInfo($My_Hwnd, $aList[$i][1], "askfilename:") ConsoleWrite('$CurrentFile = ' & $CurrentFile & @CRLF) $CurrentFile = StringReplace($CurrentFile, "filename:", "") If StringInStr($cmdlineraw, $CurrentFile) Then ; When the current filename is the same as the file being processed by AutoIt3wrapper. then select the handle $SciTE_hwnd = $aList[$i][1] ExitLoop EndIf Next ConsoleWrite('- $SciTE_hwnd: ' & $SciTE_hwnd & @CRLF) EndFunc ; Received Data from SciTE Func MY_WM_COPYDATA($HWindow, $msg, $wParam, $lParam) #forceref $HWindow, $msg, $wParam Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam) Local $SciTECmdLen = DllStructGetData($COPYDATA, 2) Local $CmdStruct = DllStructCreate('Char[255]', DllStructGetData($COPYDATA, 3)) $g_SciTECmd = StringFormat(StringLeft(DllStructGetData($CmdStruct, 1), $SciTECmdLen)) ConsoleWrite('<--' & $g_SciTECmd & @CRLF) EndFunc ;==>MY_WM_COPYDATA Func SendSciTE_Command($My_Hwnd, $SciTE_hwnd, $sCmd) Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']') DllStructSetData($CmdStruct, 1, $sCmd) Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr') DllStructSetData($COPYDATA, 1, 1) DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1) DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct)) DllCall('User32.dll', 'None', 'SendMessageA', 'HWnd', $SciTE_hwnd, _ 'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _ 'Ptr', DllStructGetPtr($COPYDATA)) ConsoleWrite('-->' & $sCmd & @CRLF) EndFunc ;==>SendSciTE_Command ; Func SendSciTE_GetInfo($My_Hwnd, $SciTE_hwnd, $sCmd) Local $My_Dec_Hwnd = Dec(StringTrimLeft($My_Hwnd, 2)) $sCmd = ":" & $My_Dec_Hwnd & ":" & $sCmd $g_SciTECmd = "" SendSciTE_Command($My_Hwnd, $SciTE_hwnd, $sCmd) For $x = 1 To 10 If $g_SciTECmd <> "" Then ExitLoop Sleep(20) Next $g_SciTECmd = StringTrimLeft($g_SciTECmd, StringLen(":" & $My_Dec_Hwnd & ":")) $g_SciTECmd = StringReplace($g_SciTECmd, "macro:stringinfo:", "") Return $g_SciTECmd EndFunc ;==>SendSciTE_GetInfo #Region code on bottom Func OnAutoItBye() ShellHookWindow($My_Hwnd, 0) GUIRegisterMsg($WM_INPUT, '') GUIRegisterMsg($WM_SETTINGCHANGE, '') GUIDelete() EndFunc Func ON_MOUSEDCLICK() $g_aSystemMetrics_MainButton_DownUp[3] = 1 AdlibUnRegister("ON_MOUSEDCLICK") If $g_WinActiveInfo[2] = "SciTEWindow" Then Do Local $hScintilla2 = ControlGetHandle($g_WinActiveInfo[0], "", "Scintilla2") If @error Then ExitLoop Local $aScintilla2Pos = WinGetPos($hScintilla2) If @error Then ExitLoop If $g_MousePos_last[0] > $aScintilla2Pos[0] And _ $g_MousePos_last[1] > $aScintilla2Pos[1] And _ $g_MousePos_last[0] < $aScintilla2Pos[0] + $aScintilla2Pos[2] And _ $g_MousePos_last[1] < $aScintilla2Pos[1] + $aScintilla2Pos[3] Then ;~ ConsoleWrite('+ Func ON_MOUSEDCLICK() - X: ' & $aScintilla2Pos[0] & " - Y: " & $aScintilla2Pos[1] & " - W: " & $aScintilla2Pos[2] & " - H: " & $aScintilla2Pos[3] & @CRLF) DoTheSciteStuff() EndIf Until 1 = 1 EndIf $g_aSystemMetrics_MainButton_DownUp[3] = 0 EndFunc Func ON_SETTINGCHANGE() AdlibUnRegister("ON_SETTINGCHANGE") ;~ ConsoleWrite('+ Func ON_SETTINGCHANGE()' & @CRLF) If _WinAPI_GetSystemMetrics($SM_SWAPBUTTON) Then $g_aSystemMetrics_MainButton_DownUp[0] = $RI_MOUSE_RIGHT_BUTTON_DOWN $g_aSystemMetrics_MainButton_DownUp[1] = $RI_MOUSE_RIGHT_BUTTON_UP Else $g_aSystemMetrics_MainButton_DownUp[0] = $RI_MOUSE_LEFT_BUTTON_DOWN $g_aSystemMetrics_MainButton_DownUp[1] = $RI_MOUSE_LEFT_BUTTON_UP EndIf $g_aSystemMetrics_MainButton_DownUp[2] = _WinAPI_GetDoubleClickTime() EndFunc ;==>ON_SETTINGCHANGE Func WM_SETTINGCHANGE($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam AdlibRegister("ON_SETTINGCHANGE", 1000) ; no hurrys EndFunc ;==>WM_SETTINGCHANGE Func WM_INPUT($hWnd, $iMsg, $wParam, $lParam) ;~ ConsoleWrite('+ Func WM_INPUT(' & $hWnd & ', ' & $iMsg & ', ' & $wParam & ', ' & $lParam & ')' & @CRLF) #forceref $iMsg, $wParam Switch $hWnd Case $My_Hwnd Local $tRIM = DllStructCreate($tagRAWINPUTMOUSE) If _WinAPI_GetRawInputData($lParam, $tRIM, DllStructGetSize($tRIM), $RID_INPUT) Then Local $aMousePos = MouseGetPos() If Not @error Then Local $iFlags = DllStructGetData($tRIM, 'ButtonFlags') If BitAND($iFlags, $g_aSystemMetrics_MainButton_DownUp[0]) Then ;~ ConsoleWrite('+ ' & $aMousePos[0] & ',' & $aMousePos[1] & @CRLF) If TimerDiff($g_MousePos_last[2]) < $g_aSystemMetrics_MainButton_DownUp[2] And _ $g_MousePos_last[0] = $aMousePos[0] And _ $g_MousePos_last[1] = $aMousePos[1] And _ $g_aSystemMetrics_MainButton_DownUp[3] = 0 Then AdlibRegister("ON_MOUSEDCLICK", 10) ElseIf BitAND($iFlags, $g_aSystemMetrics_MainButton_DownUp[1]) Then ;~ ConsoleWrite('- ' & $aMousePos[0] & ',' & $aMousePos[1] & @CRLF) $g_MousePos_last[0] = $aMousePos[0] $g_MousePos_last[1] = $aMousePos[1] $g_MousePos_last[2] = TimerInit() EndIf EndIf EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_INPUT Func _WinAPI_GetDoubleClickTime() ; https://www.autoitscript.com/forum/topic/48593-mouse-doubleclick-time/ Local $Ret = DllCall('user32.dll', 'uint', 'GetDoubleClickTime') If @error Then Return SetError(1, 0, 500) Return $Ret[0] EndFunc ;==>_WinAPI_GetDoubleClickTime #EndRegion code on bottom