VB6.0怎么判断鼠标的左键被按下?
展开全部
一、新建一个模块,复制下面代码:
Option Explicit
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WH_MOUSE_LL = 14
Public Const WM_LBUTTONDOWN = &H201
Public lHook(1) As Long
Public Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim fEatKeystroke As Boolean
Select Case wParam
Case WM_LBUTTONDOWN
Debug.Print "鼠标的左键被按下"
End Select
If fEatKeystroke Then
LowLevelMouseProc = -1
Else
LowLevelMouseProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End Function
二、调用举例:
Private Sub Form_Load()
lHook(1) = SetWindowsHookEx(WH_MOUSE_LL, AddressOf LowLevelMouseProc, App.hInstance, 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx lHook(1)
End Sub
Option Explicit
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WH_MOUSE_LL = 14
Public Const WM_LBUTTONDOWN = &H201
Public lHook(1) As Long
Public Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim fEatKeystroke As Boolean
Select Case wParam
Case WM_LBUTTONDOWN
Debug.Print "鼠标的左键被按下"
End Select
If fEatKeystroke Then
LowLevelMouseProc = -1
Else
LowLevelMouseProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End Function
二、调用举例:
Private Sub Form_Load()
lHook(1) = SetWindowsHookEx(WH_MOUSE_LL, AddressOf LowLevelMouseProc, App.hInstance, 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx lHook(1)
End Sub
展开全部
定义一个全局变量,在mouseDown事件里使其=true,在mouseUp事件里使其=false
然后通过判断这个变量就知道鼠标是否是按下了
然后通过判断这个变量就知道鼠标是否是按下了
追问
晕 我是说指的是在窗体外面按的时候!在窗体里谁不会啊!
追答
那你就得写服务了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
api
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询