|
-
Nov 1st, 2003, 05:29 PM
#1
Thread Starter
Lively Member
Mouse Click Anywhere
How can I find out When and Where the Mouse Button is clicked Anywhere on the Screen, Reguardless of what is Under the Mouse Pointer?
-
Nov 2nd, 2003, 06:36 AM
#2
Member
Hi,
Just a small clarification...
When u say "screen", do u mean the "form" or the screen which includes the titlebar and the control buttons?
Bye & regards
Ravi.
-
Nov 2nd, 2003, 12:42 PM
#3
Thread Starter
Lively Member
I mean the whole Screen, The form takes up the whole screen, there is no Title Bar or anything, just the form.
But I dont want to use a Form_click b/c I want to know when they click anywhere.
-
Nov 11th, 2003, 04:54 PM
#4
Thread Starter
Lively Member
-
Nov 11th, 2003, 05:45 PM
#5
Here is one way.
If you after other SubClassing examples, do a search using KeyWords: mouse hooks
Bruce.
-
Nov 11th, 2003, 06:45 PM
#6
Fanatic Member
Or if you dont want to screw with hooks and having to dowload extra DLLs and stuff you could do it with this code and these APIs.
This Code would go in a form with 2 labels and a timer named Label1, Label2 and Timer1
VB Code:
Private Sub Timer1_Timer()
GetCursorPos mPoint
Label1.Caption = "X: " & mPoint.x & " Y: " & mPoint.y
If GetAsyncKeyState(1) Then
Label2.Caption = "Left Mouse Button Down"
Else
Label2.Caption = ""
End If
End Sub
This code would go in a module
VB Code:
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Type POINTAPI
x As Long
y As Long
End Type
Global mPoint As POINTAPI
This would return the x and y based on screen coordinates and the getasynckeystate(1) is watching the left mouse button.. you would need a (2) and an (8) for right and middle.
The two faults to this code.. one clicking on window controls (minimize maximize and exit) are not registered.. but if your fullscreen without a titlebar you dont need to worry about that. The Second fault is you have a timer executing constantly whlie not a big issue with this small of code if you had a large amount of code in the timer it could cause perfomance issues.
Last edited by StevenHickerson; Nov 11th, 2003 at 06:50 PM.
-
Nov 25th, 2003, 05:35 AM
#7
Addicted Member
i don't mean to sound stupid.. if i do.. but isn't that a hook?
C++/VB6&.NET/QBasic/HTML/PHP/MySQL/SQLServer2k
I'm the guy your little brother looks a lot alike. Tell your mom i said thanks.
naked in vegas
-
Nov 25th, 2003, 06:09 AM
#8
No it isn't a hook, although it does the same thing as the hooking code that Bruce Fox linked to.
Hooking is telling Windows to send the messages to your code before it sends them on to the proper place. This gives you the chance to alter the messages (eg: when the left mouse button is pressed you could tell the target program that the right mouse button was pressed, or that no button was pressed).
StevenHickersons code just repeatedly checks the current state - which may or may not capture all of the events (depending on the timer interval and how busy the computer is). Hooking is guaranteed to get all events, but is a little harder to work with.
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
|