8 Replies Latest reply on Apr 8, 2016 8:01 AM by mjohnson

    How to get mouse position in DxD / xDx?


      I am trying to write some automation that either attaches things to the mouse pointer, or drops them down at the current mouse location. Anyone know how to do either of these? I see some events related to the mouse moving, but not sure how to proceed. I have all the other automation relatively in place.

        • 1. Re: How to get mouse position in DxD / xDx?

          If you are using a .net compiler, this is how you would do it:


          Public WithEvents app as ViewDraw.Application


          Public Sub mousemoved(ByVal Flags As Long, ByVal X As Long, ByVal Y As Long) Handles app.MouseMoved

               x1 = CDbl(X / 25400)

               y1 = CDbl(Y / 25400)

          End Sub


          The units conversion from display units to sheet units is 1:100, so the display units will be x1 / 100, y1 / 100, to display inches.


          Now if you are using a scripting language, with an EFM or vbscript, it's different.  Search for 'events' in the DxDesigner Automation Reference Manual for examples on how to do it. There are also examples in the ScriptingClass_99.ppt file included with AATK

          2 of 2 people found this helpful
          • 2. Re: How to get mouse position in DxD / xDx?

            I wanted to avoid using the MouseMoved event, hoping there was something else I could use, but I'll look into using this. Thanks!

            • 3. Re: How to get mouse position in DxD / xDx?

              One thing to be aware of here is that there is a difference between the mouse, with all of the interaction your computer does with it, and the cursor position on the screen.  Trying to get the actual data passed by the mouse is resource intensive and complicated.  On the other hand, letting the OS do its job and just getting the result of the cursor location in a window is much easier and uses a lot less CPU cycles.


              The example above demonstrates getting the information from a window, with all the heavy lifting already done upstream.

              • 4. Re: How to get mouse position in DxD / xDx?

                I've been assuming that DxD reports the position where the mouse is (say,

                when a right-click occurs to bring up the context menu in a DxD window).

                I'll have to try the MouseMoved event to see if I can figure out what gets

                reported, but I'm assuming those are DxD X and Y coordinates. If you have

                another suggestion, please let me know.

                • 5. Re: How to get mouse position in DxD / xDx?

                  Yes, they are coordinates from the DxDesigner window.  All the hard work is already done for you.  Just stick with that and you'll be fine. 


                  I posted the part about the difference between the mouse and the cursor only as a warning, because I once wasted a lot of time attacking the "mouse" position the wrong way, when what I really needed was the cursor position.  I hadn't realized there was a difference until then.  Sometimes we use the terms as if they are interchangeable, when to the OS they are not.

                  • 6. Re: How to get mouse position in DxD / xDx?

                    Still having trouble with this; I can't find an example of how Application_MouseMoved() is actually used. I've successfully gotten other events to work, but not this one. What is the syntax, e.g., if I want to append output of the X,Y position to the output window whenever the mouse is right-clicked?


                    Also, it appears I have multiple Application_MouseMoved events planned. How can I clear one event, so that I can set different conditions for the next one? E.g., I may start an event, looking for certain conditions, then I want to start another event monitor, looking for different conditions.

                    • 7. Re: How to get mouse position in DxD / xDx?

                      Now you are getting more complicated.  If you look at the help for DxDesigner Automation, and look at the Application object, you will see that while there is an application event for moving the mouse, there is none for clicking or doing anything else with the mouse.


                      Which means you will now have to use mouse events from the operating system, and combine them with events from DxDesigner.  And, using the OS mouse events is kind of tricky, as I alluded to above.  If you start from scratch, it will take you many hours of research and trial and error to come up with a .net project that works and includes functioning bits for all the stuff you will need to do.  There is no simple solution here, and much of what you encounter will appear to be unfathomable unless you either have many years of .net experience or have a degree in software engineering. 


                      Fortunately for you, I have already done all that. I have a vb.net project with everything in it you would need to capture all mouse events from the OS, and I will share it with you. Send me a message through the forum here and we'll work out the details.


                      Now, about your second paragraph.  You don't clear events.  They happen, and the code in the event handler executes. Every time.  A series of if/then statements can send the event handler down many different paths. You can set variables and controls any way you like to alter the course of the event handler's path, and thus effect different outcomes. The event handler must be thought of as a response that happens every time the event fires, making no assumptions about anything, but evaluating everything it needs to in order to accomplish what you want. 


                      If you give us an idea of what you are actually trying to do, we may be able to point you in the right direction as to how to accomplish it. 

                      1 of 1 people found this helpful
                      • 8. Re: How to get mouse position in DxD / xDx?

                        I'm trying to detect the mouse position at the point of the right-click, so that I can place text there, direct a form to open up there, etc. I found that the MouseMoved event can trigger on the mouse moving while the right mouse button is down, but not actually capture the "mouse clicked" event".