Is there a way to detect whether an event was triggered using input devices or via script as in .onEvent()?
Is there a way to detect whether an event was triggered using inpu开发者_如何学Pythont devices or via script as in .onEvent()
?
Short story, no.
The only thing you can examine is the event object
which is passed into a callback handler (the "event handler"). Like typeof suggested in his answer, there might be propertys which aren't set if the event was triggered by device (or vice versa), but then again it's 100% NOT reliable. Example:
$('someinputcontrol').trigger({
type: 'keydown',
originalEvent: true
});
You can add any property to the event object using this technique. So again, there is no reliable way to detect whether an event was fired due to device or script.
Looks like you can inspect the event object passed to the event handler to see if it was an artificial event or not:
if(event.originalEvent) {
...
}
It seems like the event object will have a property called originalEvent if the event was triggered by input device rather than script.
精彩评论