English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

用vb6.0寫要如何偵測滑鼠按鍵(是按左鍵還是按右鍵)
我想寫一個程式 , 可以偵測我是按下滑鼠的哪一個按鍵 , (不是在我的表單上按喔!) 是在我程式的表單以外的地方按喔!
各位前輩請多多指教喔!

2006-04-27 09:07:45 · 1 個解答 · 發問者 Nick 5 in 電腦與網際網路 程式設計

1 個解答

'以下在表單Private Sub Form_Load()AutoRedraw = TrueH = SetWindowsHookEx(0, AddressOf HP, App.hInstance, 0)End SubPrivate Sub Form_Unload(Cancel As Integer)UnhookWindowsHookEx HEnd Sub'以下在模組Const WM_LBUTTONDOWN = &H201Const WM_RBUTTONDOWN = &H204Type EVENTMSG        message As Long        paramL As Long        paramH As Long        time As Long        hWnd As LongEnd TypeDeclare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (L As Any, ByVal S&, ByVal C&)Declare Function CallNextHookEx Lib "user32" (ByVal H&, ByVal n&, ByVal W&, L As Any) As LongDeclare Function CloseHandle Lib "kernel32" (ByVal H&) As LongDeclare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal k&, ByVal L&, ByVal H&, ByVal d&) As LongDeclare Function UnhookWindowsHookEx Lib "user32" (ByVal H&) As LongPublic H As LongFunction HP(ByVal C As Long, ByVal W As Long, ByVal L As Long) As LongDim I As Long, M As EVENTMSG, J As LongIf C = 0 Then   CopyMemory M, L, LenB(M)   If M.message = WM_LBUTTONDOWN Then      Form1.Print "你按下滑鼠左鍵"   ElseIf M.message = WM_RBUTTONDOWN Then      Form1.Print "你按下滑鼠右鍵"   End IfEnd IfHP = CallNextHookEx(H, C, W, L)End Function

2006-04-27 09:51:59 · answer #1 · answered by W.J.S. 7 · 0 0

fedest.com, questions and answers