Results 1 to 8 of 8

Thread: Mouse Click Anywhere

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    Canada
    Posts
    86

    Red face 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?

  2. #2
    Member
    Join Date
    Jun 2002
    Location
    India
    Posts
    40
    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    Canada
    Posts
    86
    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.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    Canada
    Posts
    86
    Bump.

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Here is one way.

    If you after other SubClassing examples, do a search using KeyWords: mouse hooks



    Bruce.

  6. #6
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586
    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:
    1. Private Sub Timer1_Timer()
    2.     GetCursorPos mPoint
    3.     Label1.Caption = "X: " & mPoint.x & "  Y: " & mPoint.y
    4.     If GetAsyncKeyState(1) Then
    5.         Label2.Caption = "Left Mouse Button Down"
    6.     Else
    7.         Label2.Caption = ""
    8.     End If
    9. End Sub

    This code would go in a module
    VB Code:
    1. Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    2. Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    3.  
    4. Public Type POINTAPI
    5.     x As Long
    6.     y As Long
    7. End Type
    8.  
    9. 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.

  7. #7
    Addicted Member Para80d's Avatar
    Join Date
    Oct 2003
    Location
    Denton, TX
    Posts
    160
    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

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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
  •  



Click Here to Expand Forum to Full Width