Use the which
property of the event object. It should be undefined
for code-triggered events:
$("#someElem").click(function(e) {
if(e.which) {
//Actually clicked
}
else {
//Triggered by code
}
});
Here's a working example of the above.
Update based on comments
Pressing the Enter key when an input
element has focus can trigger the click
event. If you want to distinguish between code-triggered clicks and all other clicks (mouse or keyboard triggered) then the above method should work fine.