With jQuery it's easy. With pure JavaScript isn't, at least it isn't easy to find out how. if (event.clientX && event.clientY) { ... } gives kind-of detection, but it's not 100% accurate.
There is a way, but it's quite controversial IMHO. Try this:
HTMLElement.prototype.dispatchEvent = (function(dispev) {
return function(event) {
// Do your stuff
dispev.call(this, event);
};
})(HTMLElement.prototype.dispatchEvent);
With this, you're able to catch every call to dispatchEvent when a programmatically generated event is dispatched. Of course, this would slow down a bit the dispatching, but shouldn't be a problem unless you're trying to fire a lot of events.
In IE8 you must replace Element.prototype.fireEvent instead, while in IE7 and lower it's just not possible to do anything about it.
Event.isTrusted can be used upto a satisfactory level.
来源:https://stackoverflow.com/questions/16178675/how-to-check-if-mouse-click-event-is-simulated-or-is-native-non-jquery-way