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. C#
  4. I need to get mouse events anywhere on the screen

I need to get mouse events anywhere on the screen

Scheduled Pinned Locked Moved C#
question
7 Posts 4 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
    Anonymous
    wrote on last edited by
    #1

    I need to catch mouse events, even when the mouse is not over any of my forms or controls. Ideally, I could selectively choose to either pass on the message to the window that should have gotten it, or trap it. Anybody have an idea?

    S L 2 Replies Last reply
    0
    • A Anonymous

      I need to catch mouse events, even when the mouse is not over any of my forms or controls. Ideally, I could selectively choose to either pass on the message to the window that should have gotten it, or trap it. Anybody have an idea?

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      Fortunately, there is no C# way of doing this : mouse events are attached to controls.


      if you start putting in too manay features, it no longer remains useful for beginners quote in a CP article comment, shiraz baig

      A 1 Reply Last reply
      0
      • S Stephane Rodriguez

        Fortunately, there is no C# way of doing this : mouse events are attached to controls.


        if you start putting in too manay features, it no longer remains useful for beginners quote in a CP article comment, shiraz baig

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

        Can I do it using interop?

        1 Reply Last reply
        0
        • A Anonymous

          I need to catch mouse events, even when the mouse is not over any of my forms or controls. Ideally, I could selectively choose to either pass on the message to the window that should have gotten it, or trap it. Anybody have an idea?

          L Offline
          L Offline
          Li kai Liu Angus
          wrote on last edited by
          #4

          I don't if it works or not. Because I've never used this feature Correct me if I am wrong:) There is a property called Capture in Control Class. It can be set to true if you wish to capture all mouse events, even outside the control's borders. The following text is copied from MSDN: --- When a control has captured the mouse, it receives mouse input whether or not the cursor is within its borders. The mouse is typically only captured during drag operations. Only the foreground window can capture the mouse. When a background window attempts to do so, the window receives messages only for mouse events that occur when the mouse cursor is within the visible portion of the window. Also, even if the foreground window has captured the mouse, the user can still click another window, bringing it to the foreground. When the mouse is captured, shortcut keys do not work. --- Hope this would help:-O

          L 1 Reply Last reply
          0
          • L Li kai Liu Angus

            I don't if it works or not. Because I've never used this feature Correct me if I am wrong:) There is a property called Capture in Control Class. It can be set to true if you wish to capture all mouse events, even outside the control's borders. The following text is copied from MSDN: --- When a control has captured the mouse, it receives mouse input whether or not the cursor is within its borders. The mouse is typically only captured during drag operations. Only the foreground window can capture the mouse. When a background window attempts to do so, the window receives messages only for mouse events that occur when the mouse cursor is within the visible portion of the window. Also, even if the foreground window has captured the mouse, the user can still click another window, bringing it to the foreground. When the mouse is captured, shortcut keys do not work. --- Hope this would help:-O

            L Offline
            L Offline
            Li kai Liu Angus
            wrote on last edited by
            #5

            just tested it. It looks the scope is rather limited. Even you set it true, you still can't capture mouse events outside its top parent control...

            A 1 Reply Last reply
            0
            • L Li kai Liu Angus

              just tested it. It looks the scope is rather limited. Even you set it true, you still can't capture mouse events outside its top parent control...

              A Offline
              A Offline
              Anonymous
              wrote on last edited by
              #6

              Hmmm, that isn't very helpful in this situation, but good to know overall. Anybody else?

              R 1 Reply Last reply
              0
              • A Anonymous

                Hmmm, that isn't very helpful in this situation, but good to know overall. Anybody else?

                R Offline
                R Offline
                Rupel
                wrote on last edited by
                #7

                there's useful project on "the evil other site" ;) http://www.codeguru.com/system/Lock.shtml the secret is: you need to install a system-hook. the one capturing mouse-events needs to reside in a dll. i once did that with C++ but i have no idea whether this works with C#... :~ :wq

                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