unL33T Posted May 24, 2023 Share Posted May 24, 2023 (edited) When I press the middle mouse button I want to perform some key combos, then hold a different mouse button until I release the one I am pressing, then do some more key combos without passing the original mouse button to the active window. I can get it all to work except that the button being pressed is also sent to the active window. Is this possible? I've tried a number of solutions but they all either block mouse movement (required), mess with mouse movement even when the button isn't pressed, or cause the script to think I released the button. expandcollapse popup#include <Misc.au3> Opt("WinTitleMatchMode", 2) ;match partial names of windows MsgBox($MB_SYSTEMMODAL, "Window", "Script started.") Func OneNotePan() Send("{alt}dy") MouseDown($MOUSE_CLICK_LEFT) While _IsPressed("04") ;do nothing while the middle button is held WEnd MouseUp($MOUSE_CLICK_LEFT) Send("{Alt}dt{Alt}h{Esc}{Esc}") EndFunc Func AcrobatPan() ;MsgBox($MB_SYSTEMMODAL, "Window", "Acrobat is active.") Send("{Space down}") MouseDown($MOUSE_CLICK_LEFT) While _IsPressed("04") ;do nothing while the middle button is held WEnd MouseUp($MOUSE_CLICK_LEFT) Send("{Space up}") EndFunc Func VisioPan() Send("{CtrlDown}{ShiftDown}") MouseDown($MOUSE_CLICK_RIGHT) While _IsPressed("04") ;do nothing while the middle button is held WEnd MouseUp($MOUSE_CLICK_RIGHT) Send("{CtrlUp}{ShiftUp}") EndFunc Func IdentifyApp() ;MsgBox($MB_SYSTEMMODAL, "Window", "Middle button down.") if WinActive("OneNote") Then OneNotePan() Elseif WinActive("Acrobat") Then AcrobatPan() ;MsgBox($MB_SYSTEMMODAL, "Window", "Acrobat is active.") Elseif WinActive("Visio") Then VisioPan() ;MsgBox($MB_SYSTEMMODAL, "Window", "Visio is active.") EndIf EndFunc while 1 if _IsPressed("04") Then IdentifyApp() Sleep (500) ;keep script running WEnd Edited May 30, 2023 by unL33T Link to comment Share on other sites More sharing options...
Andreik Posted May 24, 2023 Share Posted May 24, 2023 Quote passing the original mouse button to the active window What do you mean by passing the button and who is active window? When the words fail... music speaks. Link to comment Share on other sites More sharing options...
unL33T Posted May 24, 2023 Author Share Posted May 24, 2023 (edited) 20 minutes ago, Andreik said: What do you mean by passing the button and who is active window? When I click the middle mouse button I don't want the middle mouse button to be sent to whatever program is open. Just whatever I put in my script. The script performs different actions depending on which window is active. Edited May 24, 2023 by unL33T Link to comment Share on other sites More sharing options...
Solution Nine Posted May 24, 2023 Solution Share Posted May 24, 2023 (edited) Maybe something along this : expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", True) Opt("WinTitleMatchMode", 2) ;match partial names of windows Global $hHook, $hFunc, $bMiddle HotKeySet('{ESC}', _Exit) OnAutoItExitRegister(Close) Main() Func Main() $hFunc = DllCallbackRegister(MouseProc, 'lresult', 'int;int;int') $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hFunc), _WinAPI_GetModuleHandle(0)) While Sleep(10) If $bMiddle Then Switch IdentifyApp() Case 1 ; repeat for all apps ; do something before While $bMiddle Sleep(10) WEnd ; do something after Case 4 Send("notepad down" & @CR) While $bMiddle Sleep(10) WEnd Send("notepad up" & @CRLF) EndSwitch EndIf WEnd EndFunc ;==>Main Func MouseProc($iCode, $iwParam, $ilParam) If $iCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam) Switch $iwParam Case $WM_MBUTTONDOWN, $WM_MBUTTONUP If IdentifyApp() Then $bMiddle = $iwParam = $WM_MBUTTONDOWN Return 1 EndIf EndSwitch Return _WinAPI_CallNextHookEx($hHook, $iCode, $iwParam, $ilParam) EndFunc ;==>MouseProc Func _Exit() Exit EndFunc ;==>_Exit Func Close() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hFunc) EndFunc ;==>Close Func IdentifyApp() Local Static $aList[] = ["OneNote", "Acrobat", "Visio", "[CLASS:Notepad]"] For $i = 0 To UBound($aList) - 1 If WinActive($aList[$i]) Then Return $i + 1 Next EndFunc ;==>IdentifyApp Edited May 24, 2023 by Nine corrected a small bug unL33T 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
unL33T Posted May 30, 2023 Author Share Posted May 30, 2023 Thanks! I subbed my code into your sample and sure enough it works! I wish I understood more about how this works. Link to comment Share on other sites More sharing options...
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