问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

VB编程如何获取鼠标双击事件

发布网友 发布时间:2022-04-29 15:33

我来回答

4个回答

热心网友 时间:2023-10-15 21:15

Option Explicit
Private Declare Function GetDoubleClickTime Lib "user32" () As Long '获得双击时间间隔
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer '获得鼠标状态
Dim PreviousTime As Double
Dim DBClickTime As Double

Private Sub Form_Load()
DBClickTime = GetDoubleClickTime / 1000
End Sub

Private Sub Timer1_Timer() 'Timer的interval属性值设为小一点例如100
Dim IsDBClick As Boolean
If GetAsyncKeyState(1) <> 0 Then '1为左键,2为右键,4为中键
If Timer - PreviousTime < DBClickTime Then IsDBClick = True
PreviousTime = Timer
End If

If IsDBClick = True Then
'这里写当检测到鼠标双击时要执行的代码
End If
End Sub

热心网友 时间:2023-10-15 21:15

在控件上用DblClick事件啊,比如你鼠标移动的范围是在PictureBox控件上,那么就在PictureBox控件的DblClick中编程

热心网友 时间:2023-10-15 21:16

以下在模块中

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 Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)

Public Type MOUSEMSGS
X As Long 'x座标
Y As Long 'y座标
a As Long
b As Long
time As Long 'Window运行时间
End Type
Public Type POINTAPI
X As Long
Y As Long
End Type

Public Const WH_MOUSE_LL = 14

'-----------------------------------------
'消息
Public Const HC_ACTION = 0

'鼠标消息
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public MouseMsg As MOUSEMSGS
Public lHook As Long
'----------------------------------------

Private Declare Function GetDoubleClickTime Lib "user32" () As Long
'鼠标钩子
Public Function CallMouseHookProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim pt As POINTAPI, DBLCLK As Long
Static DBtime As Long
DBLCLK = GetDoubleClickTime
If code = HC_ACTION Then
CopyMemory MouseMsg, lParam, LenB(MouseMsg)

If wParam = 513 And MouseMsg.time - DBtime <= DBLCLK Then MsgBox "双击"
If wParam = 512 Then DBtime = 0
If wParam = 514 Then DBtime = MouseMsg.time

End If
If code <> 0 Then
CallMouseHookProc = CallNextHookEx(0, code, wParam, lParam)
End If

End Function

以下在 form1 中

'安装钩子
Private Sub AddHook()
'鼠标钩子
lHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf CallMouseHookProc, App.hInstance, 0)
End Sub
'卸钩子
Private Sub DelHook()
UnhookWindowsHookEx lHook
End Sub

Private Sub Command1_Click()
DelHook '卸钩子
End Sub
Private Sub Form_Load()

AddHook

End Sub

Private Sub Form_Unload(Cancel As Integer)
DelHook
End Sub

热心网友 时间:2023-10-15 21:16

双击任何位置可以用键盘钩子 SetWindowsHookEx WH_KEYBOARD KeyboardProc

热心网友 时间:2023-10-15 21:15

Option Explicit
Private Declare Function GetDoubleClickTime Lib "user32" () As Long '获得双击时间间隔
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer '获得鼠标状态
Dim PreviousTime As Double
Dim DBClickTime As Double

Private Sub Form_Load()
DBClickTime = GetDoubleClickTime / 1000
End Sub

Private Sub Timer1_Timer() 'Timer的interval属性值设为小一点例如100
Dim IsDBClick As Boolean
If GetAsyncKeyState(1) <> 0 Then '1为左键,2为右键,4为中键
If Timer - PreviousTime < DBClickTime Then IsDBClick = True
PreviousTime = Timer
End If

If IsDBClick = True Then
'这里写当检测到鼠标双击时要执行的代码
End If
End Sub

热心网友 时间:2023-10-15 21:15

Option Explicit
Private Declare Function GetDoubleClickTime Lib "user32" () As Long '获得双击时间间隔
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer '获得鼠标状态
Dim PreviousTime As Double
Dim DBClickTime As Double

Private Sub Form_Load()
DBClickTime = GetDoubleClickTime / 1000
End Sub

Private Sub Timer1_Timer() 'Timer的interval属性值设为小一点例如100
Dim IsDBClick As Boolean
If GetAsyncKeyState(1) <> 0 Then '1为左键,2为右键,4为中键
If Timer - PreviousTime < DBClickTime Then IsDBClick = True
PreviousTime = Timer
End If

If IsDBClick = True Then
'这里写当检测到鼠标双击时要执行的代码
End If
End Sub

热心网友 时间:2023-10-15 21:15

在控件上用DblClick事件啊,比如你鼠标移动的范围是在PictureBox控件上,那么就在PictureBox控件的DblClick中编程

热心网友 时间:2023-10-15 21:16

以下在模块中

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 Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)

Public Type MOUSEMSGS
X As Long 'x座标
Y As Long 'y座标
a As Long
b As Long
time As Long 'Window运行时间
End Type
Public Type POINTAPI
X As Long
Y As Long
End Type

Public Const WH_MOUSE_LL = 14

'-----------------------------------------
'消息
Public Const HC_ACTION = 0

'鼠标消息
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public MouseMsg As MOUSEMSGS
Public lHook As Long
'----------------------------------------

Private Declare Function GetDoubleClickTime Lib "user32" () As Long
'鼠标钩子
Public Function CallMouseHookProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim pt As POINTAPI, DBLCLK As Long
Static DBtime As Long
DBLCLK = GetDoubleClickTime
If code = HC_ACTION Then
CopyMemory MouseMsg, lParam, LenB(MouseMsg)

If wParam = 513 And MouseMsg.time - DBtime <= DBLCLK Then MsgBox "双击"
If wParam = 512 Then DBtime = 0
If wParam = 514 Then DBtime = MouseMsg.time

End If
If code <> 0 Then
CallMouseHookProc = CallNextHookEx(0, code, wParam, lParam)
End If

End Function

以下在 form1 中

'安装钩子
Private Sub AddHook()
'鼠标钩子
lHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf CallMouseHookProc, App.hInstance, 0)
End Sub
'卸钩子
Private Sub DelHook()
UnhookWindowsHookEx lHook
End Sub

Private Sub Command1_Click()
DelHook '卸钩子
End Sub
Private Sub Form_Load()

AddHook

End Sub

Private Sub Form_Unload(Cancel As Integer)
DelHook
End Sub

热心网友 时间:2023-10-15 21:15

Option Explicit
Private Declare Function GetDoubleClickTime Lib "user32" () As Long '获得双击时间间隔
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer '获得鼠标状态
Dim PreviousTime As Double
Dim DBClickTime As Double

Private Sub Form_Load()
DBClickTime = GetDoubleClickTime / 1000
End Sub

Private Sub Timer1_Timer() 'Timer的interval属性值设为小一点例如100
Dim IsDBClick As Boolean
If GetAsyncKeyState(1) <> 0 Then '1为左键,2为右键,4为中键
If Timer - PreviousTime < DBClickTime Then IsDBClick = True
PreviousTime = Timer
End If

If IsDBClick = True Then
'这里写当检测到鼠标双击时要执行的代码
End If
End Sub

热心网友 时间:2023-10-15 21:15

在控件上用DblClick事件啊,比如你鼠标移动的范围是在PictureBox控件上,那么就在PictureBox控件的DblClick中编程

热心网友 时间:2023-10-15 21:15

在控件上用DblClick事件啊,比如你鼠标移动的范围是在PictureBox控件上,那么就在PictureBox控件的DblClick中编程

热心网友 时间:2023-10-15 21:16

以下在模块中

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 Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)

Public Type MOUSEMSGS
X As Long 'x座标
Y As Long 'y座标
a As Long
b As Long
time As Long 'Window运行时间
End Type
Public Type POINTAPI
X As Long
Y As Long
End Type

Public Const WH_MOUSE_LL = 14

'-----------------------------------------
'消息
Public Const HC_ACTION = 0

'鼠标消息
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public MouseMsg As MOUSEMSGS
Public lHook As Long
'----------------------------------------

Private Declare Function GetDoubleClickTime Lib "user32" () As Long
'鼠标钩子
Public Function CallMouseHookProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim pt As POINTAPI, DBLCLK As Long
Static DBtime As Long
DBLCLK = GetDoubleClickTime
If code = HC_ACTION Then
CopyMemory MouseMsg, lParam, LenB(MouseMsg)

If wParam = 513 And MouseMsg.time - DBtime <= DBLCLK Then MsgBox "双击"
If wParam = 512 Then DBtime = 0
If wParam = 514 Then DBtime = MouseMsg.time

End If
If code <> 0 Then
CallMouseHookProc = CallNextHookEx(0, code, wParam, lParam)
End If

End Function

以下在 form1 中

'安装钩子
Private Sub AddHook()
'鼠标钩子
lHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf CallMouseHookProc, App.hInstance, 0)
End Sub
'卸钩子
Private Sub DelHook()
UnhookWindowsHookEx lHook
End Sub

Private Sub Command1_Click()
DelHook '卸钩子
End Sub
Private Sub Form_Load()

AddHook

End Sub

Private Sub Form_Unload(Cancel As Integer)
DelHook
End Sub

热心网友 时间:2023-10-15 21:16

双击任何位置可以用键盘钩子 SetWindowsHookEx WH_KEYBOARD KeyboardProc

热心网友 时间:2023-10-15 21:16

以下在模块中

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 Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)

Public Type MOUSEMSGS
X As Long 'x座标
Y As Long 'y座标
a As Long
b As Long
time As Long 'Window运行时间
End Type
Public Type POINTAPI
X As Long
Y As Long
End Type

Public Const WH_MOUSE_LL = 14

'-----------------------------------------
'消息
Public Const HC_ACTION = 0

'鼠标消息
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public MouseMsg As MOUSEMSGS
Public lHook As Long
'----------------------------------------

Private Declare Function GetDoubleClickTime Lib "user32" () As Long
'鼠标钩子
Public Function CallMouseHookProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim pt As POINTAPI, DBLCLK As Long
Static DBtime As Long
DBLCLK = GetDoubleClickTime
If code = HC_ACTION Then
CopyMemory MouseMsg, lParam, LenB(MouseMsg)

If wParam = 513 And MouseMsg.time - DBtime <= DBLCLK Then MsgBox "双击"
If wParam = 512 Then DBtime = 0
If wParam = 514 Then DBtime = MouseMsg.time

End If
If code <> 0 Then
CallMouseHookProc = CallNextHookEx(0, code, wParam, lParam)
End If

End Function

以下在 form1 中

'安装钩子
Private Sub AddHook()
'鼠标钩子
lHook = SetWindowsHookEx(WH_MOUSE_LL, AddressOf CallMouseHookProc, App.hInstance, 0)
End Sub
'卸钩子
Private Sub DelHook()
UnhookWindowsHookEx lHook
End Sub

Private Sub Command1_Click()
DelHook '卸钩子
End Sub
Private Sub Form_Load()

AddHook

End Sub

Private Sub Form_Unload(Cancel As Integer)
DelHook
End Sub

热心网友 时间:2023-10-15 21:16

双击任何位置可以用键盘钩子 SetWindowsHookEx WH_KEYBOARD KeyboardProc

热心网友 时间:2023-10-15 21:16

双击任何位置可以用键盘钩子 SetWindowsHookEx WH_KEYBOARD KeyboardProc
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
ViewSonic优派VP3268A-4K 31.5英寸显示器,细腻画质与实用功能的完美结合... ViewSonic 优派 VP3268A-4K 31.5英寸显示器-高清大屏,色彩真实,适合多... 帮忙写一篇 读书的快乐 的作文,很急!谢谢! 以《我为什么读书》为题,写一篇作文,大家帮帮忙,谢谢了谢谢了 好书伴我成长征文, 急!! 电脑课程配置动画专业需要怎样的电脑配置 宁德时代在湖南哪个地方 伸缩自如,多场景应对,纳拓悟空露营灯开箱使用体验 欧派橱柜和奇美橱柜哪个好 奇美雅阁橱柜怎么样 女老师简笔画右面怎么画 c语言怎么判断是否点击了鼠标,简单一点的方法,dev c++可以用的,谢谢各位大神。 为什么鼠标单击=双击? 戴眼镜的老师简笔画女步骤 别人微信里收藏了我的视频,怎么能让这这视频无效 请问干式变压器都用到哪些绝缘材料(详细清单)? 戴眼镜的老师简笔画男步骤 干式变压器工程量清单描述包含哪些内容 xs和8p的区别是什么? 出自《论语》的27个成语典故,值得收藏 出自历史典故的成语故事(故事内容,出自……里,名字。) iphone xs和8plus哪个更好? ”过目不忘”是出自什么典故? “季布一诺”出自什么典故? 家里经常突然断电,不跳闸, 智能断路器停电不跳闸怎么实现 出自典故的词语 “鸿雁传书”是出自哪个典故? 数典忘祖出自那个典故 北京众诚易居物业管理有限公司怎么样? 鼠标进水了? 苹果13电信有合约机吗 如何赞美老师帮孩子梳头发 变压器厂家有哪些? 电信iphone13pro合约机套餐 老师老师让学生把头发扎起来学生不肯听话怎样才能让学生把头发扎起来呢? 干式变压器日常检查项目有哪些? 电信苹果13什么时候出合约机 想在苹果官网买的苹果13支持电信卡移动卡和联通卡吗? 干式变压器的试验项目 幼儿老师在教课期间,一定要把头发扎起来吗? 苹果13pro合约机哪个运营商好 变压器进场都需要检查什么? 苹果13合约机可以插别的卡吗 两句一押,双句押韵,一三四押,有什么区别? 租房一押三付什么意思 为什么iphone13移动合约机比官网便宜 租期为一年,一押一租 具体是什么意思 键盘进水,鼠标动不了 苹果13合约机套餐详情