I am now making a device template in perspective and the template has an event onMouseDown which toggles an OPC tag. I also wanted to make a second event onDoubleClick to be able to open a pop-up view with the setups for this specific device. So I’ve encountered an issue, that the onMouseDown event is also triggered when I double click.
I wonder if there is a way to somehow prioritize the events?
You can try using an onClick event, but I don't know if the framework is in place to prevent a double click from also triggering an onClick.
The onMouseDown event, isn't the proper place for something that you want to occur after a click (meaning both a mouseDown and mouseUp event occur). That a double click or even a single click trigger the onMouseDown is by design.
In Designer, create an event on the view or on a component.
Add a script to onMouseDown, onClick and onDoubleClick. system.perspective.print("onMouseDown"") system.perspective.print("onClick"") system.perspective.print("onDoubleClick"")
Start Designer's Preview Mode.
Open Tools | Console.
Now slowly test a single-click. You'll get,
14:08:28.364 [Browser Thread: ...] INFO ... -- onMouseDown
14:08:28.420 [Browser Thread: ...] INFO ... -- onClick
Note that the onClick event is logged on mouse release.
Now test a double-click.
14:10:38.745 [Browser Thread: ...] INFO ... -- onMouseDown
14:10:38.816 [Browser Thread: ...] INFO ... -- onClick
14:10:38.891 [Browser Thread: ...] INFO ... -- onMouseDown
14:10:38.994 [Browser Thread: ...] INFO ... -- onClick
14:10:38.995 [Browser Thread: ...] INFO ... -- onDoubleClick
This just confirms what you're seeing. I haven't thought of a fix yet. The double-click is announced 1 ms after the second onClick. (It may be different in a browser rather than a Designer.)
Note that, in general, window GUIs have to wait for mouse release to determine whether a click is part of a drag operation rather than a simple click, so the event is usually triggered on the button release. (This was a major slowdown when switching from DOS CAD systems to Windows as you had to click and release on the control - way back!)
As a project design pointer, you should try to avoid using one piece of interactive UI to accomplish multiple actions. At the very least, you should avoid “overlapping” actions
Think of a link or button on a web page. They accept only one click, or an alt-click (right click) and both of those different interactions perform different tasks. Trying to double-click a link will do nothing for you.
Either place a secondary piece of UI to open the popup, or use something like onContextMenu to open your popup when the user right-clicks.
Alternatively, you could also use the built-in context menu props to handle this in a more “native” approach.
Thanks a lot for your answers! I wanted to avoid extra piece of UI (like a button) and was hoping to complete the task with multiple events.
The right click seems like a suitable option for a PC with a mouse. On a touch screen it might get a little bit complicated since the right click is associated with a “long” touch. I have some components that require to be pushed down to activate some devices functions like manual jogging of a motor. I will experiment with some of the ideas and post them in this topic.
I hope you're not trying to do this in perspective. there are many topics on this on the forum about why this is doomed to fail and leave your jogging tag high