Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Hooking the Mouse

Hooking the Mouse

Scheduled Pinned Locked Moved Visual Basic
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndrewVos
    wrote on last edited by
    #1

    I am trying to write a piece of code that spawns a window when the user presses both mouse buttons simultaneously. I have been thinking the only way to do this would be to have two mouse hooks, watching for left and right clicks respectively, and checking the time difference between clicks. It would then cancel the message if the time is within a certain interval, and show the window. Any better ideas? Please?


    All your source are belong to us!

    K 1 Reply Last reply
    0
    • A AndrewVos

      I am trying to write a piece of code that spawns a window when the user presses both mouse buttons simultaneously. I have been thinking the only way to do this would be to have two mouse hooks, watching for left and right clicks respectively, and checking the time difference between clicks. It would then cancel the message if the time is within a certain interval, and show the window. Any better ideas? Please?


      All your source are belong to us!

      K Offline
      K Offline
      Keith Malwitz
      wrote on last edited by
      #2

      The easiest way would be to handle the click event and check the state of the buttons inside the event. The following will close the form if both buttons are depressed: Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e _ As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick If e.Button = Windows.Forms.MouseButtons.Left Then If MouseButtons = Windows.Forms.MouseButtons.Right Then Me.Close() End If End If If e.Button = Windows.Forms.MouseButtons.Right Then If MouseButtons = Windows.Forms.MouseButtons.Left Then Me.Close() End If End If End Sub Hope this helps. Keith

      A 1 Reply Last reply
      0
      • K Keith Malwitz

        The easiest way would be to handle the click event and check the state of the buttons inside the event. The following will close the form if both buttons are depressed: Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e _ As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick If e.Button = Windows.Forms.MouseButtons.Left Then If MouseButtons = Windows.Forms.MouseButtons.Right Then Me.Close() End If End If If e.Button = Windows.Forms.MouseButtons.Right Then If MouseButtons = Windows.Forms.MouseButtons.Left Then Me.Close() End If End If End Sub Hope this helps. Keith

        A Offline
        A Offline
        AndrewVos
        wrote on last edited by
        #3

        There would be no form present when watching for mouse clicks. This is why I have suggested using a mouse hook.


        All your source are belong to us!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups