作者ward (蹲在人面狮身像里)
看板EzHotKey
标题Re: [-AI-] 滑鼠中键和滚轮
时间Tue May 4 17:46:57 2010
※ 引述《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
1F:推 iscondor:好厉害啊,我研究後有问题再与您请教,感恩 05/04 20:00