Re: [-AI-] 滑鼠中鍵和滾輪

看板EzHotKey作者 (蹲在人面獅身像裡)時間15年前 (2010/05/04 17:46), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《iscondor ()》之銘言: : 請問autoit可以寫出"按滑鼠中鍵或是滾輪上/下,輸出某個按鍵(例如enter)"等功能嗎? : 我看autoit的help檔中MouseClick和MouseWheel等介紹, : 感覺好像是在說用其他條件來啟動滑鼠的動作, : 而非用滑鼠的動作來啟動要執行的事項,不知小弟了理解是否正確? 用基本的函式沒辦法做到,要去掛 Hook 才行,範例如下 因為是臨時寫的,訊息機制就寫的很隨便,只用 Array 弄一弄 不然應該有更好的做法 檔案下載: http://ppt.cc/eEMM ; ------------------------------------------------------------------ ; HotMouse Demo ; Purpose: Just like HotKey, but use mouse to invoke functions ; Author: Ward ; ------------------------------------------------------------------ #Include <Array.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> HotKeySet("{ESC}", "_Close") Func OnMouseLeftDown($X, $Y) ToolTip("LeftDown", $X, $Y) EndFunc Func OnMouseLeftUp($X, $Y) ToolTip("LeftUp", $X, $Y) EndFunc Func OnMouseMiddleDown($X, $Y) ToolTip("MiddleDown", $X, $Y) EndFunc Func OnMouseMiddleUp($X, $Y) ToolTip("MiddleUp", $X, $Y) EndFunc Func OnMouseRightDown($X, $Y) ToolTip("RightDown", $X, $Y) EndFunc Func OnMouseRightUp($X, $Y) ToolTip("RightUp", $X, $Y) EndFunc Func OnMouseWheelDown($X, $Y) ToolTip("WheelDown", $X, $Y) EndFunc Func OnMouseWheelUp($X, $Y) ToolTip("WheelUp", $X, $Y) EndFunc ; ------------------------------------------------------------------ Global $EnableEvent = True Global $Event[1] = [0] Global $Func = DllCallbackRegister("_LowLevelMouseProc", "int", "int;wparam;lparam") Global $Hook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($Func), _WinAPI_GetModuleHandle(0)) While 1 If $Event[0] And Mod($Event[0], 3) = 0 Then $EnableEvent = False Call($Event[1], $Event[2], $Event[3]) _ArrayDelete($Event, 1) _ArrayDelete($Event, 1) _ArrayDelete($Event, 1) $Event[0] -= 3 $EnableEvent = True EndIf Sleep(20) WEnd Func _Close() _WinAPI_UnhookWindowsHookEx($Hook) DllCallbackFree($Func) Exit EndFunc Func _LowLevelMouseProc($Code, $wParam, $lParam) Local $MSLLHOOKSTRUCT = DllStructCreate("uint x; uint y; uint mouseData; uint flags; uint time; ptr dwExtraInfo", $lParam) If $EnableEvent Then If $Code < 0 Then Return _WinAPI_CallNextHookEx($Hook, $Code, $wParam, $lParam) If $wParam <> $WM_MOUSEMOVE Then Local $X = DllStructGetData($MSLLHOOKSTRUCT, "x") Local $Y = DllStructGetData($MSLLHOOKSTRUCT, "y") Local $MouseData = DllStructGetData($MSLLHOOKSTRUCT, "mouseData") Switch $wParam Case $WM_LBUTTONDOWN _ArrayAdd($Event, "OnMouseLeftDown") _ArrayAdd($Event, $X) _ArrayAdd($Event, $Y) $Event[0] += 3 Case $WM_LBUTTONUP _ArrayAdd($Event, "OnMouseLeftUp") _ArrayAdd($Event, $X) _ArrayAdd($Event, $Y) $Event[0] += 3 Case $WM_MBUTTONDOWN _ArrayAdd($Event, "OnMouseMiddleDown") _ArrayAdd($Event, $X) _ArrayAdd($Event, $Y) $Event[0] += 3 Case $WM_MBUTTONUP _ArrayAdd($Event, "OnMouseMiddleUp") _ArrayAdd($Event, $X) _ArrayAdd($Event, $Y) $Event[0] += 3 Case $WM_RBUTTONDOWN _ArrayAdd($Event, "OnMouseRightDown") _ArrayAdd($Event, $X) _ArrayAdd($Event, $Y) $Event[0] += 3 Case $WM_RBUTTONUP _ArrayAdd($Event, "OnMouseRightUp") _ArrayAdd($Event, $X) _ArrayAdd($Event, $Y) $Event[0] += 3 Case $WM_MOUSEWHEEL If BitShift($MouseData, 8) < 0 Then _ArrayAdd($Event, "OnMouseWheelDown") _ArrayAdd($Event, $X) _ArrayAdd($Event, $Y) $Event[0] += 3 Else _ArrayAdd($Event, "OnMouseWheelUp") _ArrayAdd($Event, $X) _ArrayAdd($Event, $Y) $Event[0] += 3 EndIf EndSwitch EndIf EndIf Return _WinAPI_CallNextHookEx($Hook, $Code, $wParam, $lParam) EndFunc -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.36.206.53

05/04 20:00, , 1F
好厲害啊,我研究後有問題再與您請教,感恩
05/04 20:00, 1F
文章代碼(AID): #1Bt-qJ4G (EzHotKey)
文章代碼(AID): #1Bt-qJ4G (EzHotKey)