- Home /
Difference between EventType.ContextClick and EventType.MouseDown with Event.button == 1?
I'm making a custom editor and have notices these two ways of doing what I would assume is the same thing. I've noticed some marginal differences such as when I show a GenericMenu with EventType.ContextClick the menu appears at the tip of the mouse but when I do this within the EventType.MouseDown event it appears from the center of the mouse.
The main issue I'm having because of this because I want the menu to appear from the tip of the mouse I've been using EventType.ContextClick but I would also like both left-click and right-click to have none button specific code on top of their separate functionality. I've tied doing this by having common code within the check for EventType.MouseDown but outside of a nested conditional that runs the left click specific code, but when I have something like an Event.Use() call in the common code it doesn't enter the EventType.ContextClick block. This makes little sense to me as from my understanding one event cant be two EventTypes so calling used on one shouldn't change the type of the other.
Am I missing something and is there a better way to get the results I would like?
Answer by Long2904 · Feb 21, 2021 at 09:13 AM
I've just tested it myself and realized that the type is EventType.ContextClick after RELEASE your right mouse button, which is different from the EventType.MouseDown (immediately when you right-click). It's more like MouseUp with button == 1, except it would be sent after the MouseUp 2 frames. Here what I've tested:
Right click some where in the custom editor.
type == EventType.MouseDown
Release the right mouse
type == EventType.MouseUp
type == EventType.Layout
type == EventType.ContextClick
Also EventType.ContextClick only works in the editor. Your GenericMenu was at the tip of the mouse only if the type was ContextClick is weird, I've tested and both of them make the menu appeared at the same position. Did you use Event.current.mousePosition or something else?