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. Getting mouse click outside form

Getting mouse click outside form

Scheduled Pinned Locked Moved C#
tutorialquestion
10 Posts 3 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.
  • J Offline
    J Offline
    jgallen23
    wrote on last edited by
    #1

    I need to get the coordinates of a click outside of my form, can anybody show me a quick example of doing this?

    C 1 Reply Last reply
    0
    • J jgallen23

      I need to get the coordinates of a click outside of my form, can anybody show me a quick example of doing this?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If you can interop it, there's a method for capturing the mouse so that you can get the first click, otherwise you need a system wide hook to catch mouse activity outside your form. Christian Graus - Microsoft MVP - C++

      J 1 Reply Last reply
      0
      • C Christian Graus

        If you can interop it, there's a method for capturing the mouse so that you can get the first click, otherwise you need a system wide hook to catch mouse activity outside your form. Christian Graus - Microsoft MVP - C++

        J Offline
        J Offline
        jgallen23
        wrote on last edited by
        #3

        could you give me an example on how to interop it?

        C 1 Reply Last reply
        0
        • J jgallen23

          could you give me an example on how to interop it?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Sure, I'll look it up for you Here[^] is a CP article on the API Here[^] is the API interop code. Christian Graus - Microsoft MVP - C++

          J 2 Replies Last reply
          0
          • C Christian Graus

            Sure, I'll look it up for you Here[^] is a CP article on the API Here[^] is the API interop code. Christian Graus - Microsoft MVP - C++

            J Offline
            J Offline
            jgallen23
            wrote on last edited by
            #5

            perfect! thanks

            1 Reply Last reply
            0
            • C Christian Graus

              Sure, I'll look it up for you Here[^] is a CP article on the API Here[^] is the API interop code. Christian Graus - Microsoft MVP - C++

              J Offline
              J Offline
              jgallen23
              wrote on last edited by
              #6

              Sorry, but actually those articles didn't help me. Are there any examples for C#?

              C S 2 Replies Last reply
              0
              • J jgallen23

                Sorry, but actually those articles didn't help me. Are there any examples for C#?

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                The SetCapture API is the only way outside of a global windows hook to capture the mouse at all outside your window. I'm not sure you can write a global hook in C#. Christian Graus - Microsoft MVP - C++

                J 1 Reply Last reply
                0
                • C Christian Graus

                  The SetCapture API is the only way outside of a global windows hook to capture the mouse at all outside your window. I'm not sure you can write a global hook in C#. Christian Graus - Microsoft MVP - C++

                  J Offline
                  J Offline
                  jgallen23
                  wrote on last edited by
                  #8

                  I'm using this code to get the mouse position with a timer interval of 10, and it works fine, I'm just not familar with the api enough to figure out how to check for clicks [DllImport("user32.dll")] static extern bool GetCursorPos(ref Point lpPoint); private void timer1_Tick(object sender, System.EventArgs e) { Point defPnt = new Point(); GetCursorPos(ref defPnt); MouseX = defPnt.X; MouseY = defPnt.Y; }

                  C 1 Reply Last reply
                  0
                  • J jgallen23

                    I'm using this code to get the mouse position with a timer interval of 10, and it works fine, I'm just not familar with the api enough to figure out how to check for clicks [DllImport("user32.dll")] static extern bool GetCursorPos(ref Point lpPoint); private void timer1_Tick(object sender, System.EventArgs e) { Point defPnt = new Point(); GetCursorPos(ref defPnt); MouseX = defPnt.X; MouseY = defPnt.Y; }

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    Yes, you can query where the mouse is at any time, perhaps there is an API like it you can call to get the button state. Christian Graus - Microsoft MVP - C++

                    1 Reply Last reply
                    0
                    • J jgallen23

                      Sorry, but actually those articles didn't help me. Are there any examples for C#?

                      S Offline
                      S Offline
                      Stefan Troschuetz
                      wrote on last edited by
                      #10

                      Take a look at this article here on Codeproject.


                      www.troschuetz.de

                      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