|
-
Jun 19th, 2000, 05:05 PM
#1
Thread Starter
Lively Member
What I want is the trigger an event whenever the user move or click with the mouse no matter where the pointer is something like to halt the screensaver back to desktop.
Thanks.
-
Jun 19th, 2000, 06:30 PM
#2
Lively Member
Here ya go.
This should help you.
Code:
Option Explicit
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Private Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Const WM_KEYDOWN = &H100
Const WM_KEYFIRST = &H100
Const WM_KEYLAST = &H108
Const WM_KEYUP = &H101
Const WM_LBUTTONDBLCLK = &H203
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const WM_RBUTTONDBLCLK = &H206
Const WM_RBUTTONDOWN = &H204
Const WM_RBUTTONUP = &H205
Const WM_MBUTTONDBLCLK = &H209
Const WM_MBUTTONDOWN = &H207
Const WM_MBUTTONUP = &H208
Const WM_MOUSEMOVE = &H200
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type Msg
hWnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Dim lEventHandle As Long
Dim aMsg As Msg
Sub Start()
lEventHandle = SetTimer(0, 0, 10, AddressOf MyTimer)
End Sub
Sub MyTimer(ByVal hWnd As Long, ByVal lngMsg As Long, ByVal lngID As Long, ByVal lngTime As Long)
KillTimer 0, lEventHandle 'Kill timer
Do While GetMessage(aMsg, 0, 0, 0) 'Gets the message
TranslateMessage aMsg 'translates it to something
DispatchMessage aMsg 'sends the message on to the system
Select Case aMsg.message
Case 275, 280:
Case WM_KEYFIRST To WM_KEYLAST:
Case WM_MOUSEMOVE:
Case WM_LBUTTONDOWN:
MsgBox "LeftMouseDown"
Case WM_RBUTTONDOWN:
MsgBox "RightMouseDown"
Case WM_LBUTTONUP:
MsgBox "LeftMouseUp"
Case WM_RBUTTONUP:
MsgBox "RightMouseUp"
Case Else:
End Select
Sleep 0&
Loop 'Loops until program is closed ( i think )
End Sub
-
Jun 27th, 2000, 05:00 PM
#3
Addicted Member
Re: Here ya go.
Thomas, I tried your code and it works fine but can you please tell me how can I use it so it can detect mouse no mather where it is (On external applications?)
Thanks
-
Jun 28th, 2000, 09:07 PM
#4
Lively Member
Where the Case LBUTTONDOWN you should be able to put your code there. I think it will trigger within your program as well as in external programs. Just do something like this:
Code:
Case WM_MOUSEMOVE:
Msgbox "You just moved your mouse."
Exit Loop 'to exit the loop
Case WM_LBUTTONDOWN:
Msgbox "You pressed the left mousebutton"
Exit Loop 'to exit the loop
-
Jun 29th, 2000, 01:39 AM
#5
Addicted Member
I am afraid it dos not work on external applications.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|