CheckBox--clicked vs. set programmatically

Is there
way for a CheckBox to know whether it was clicked by a mouse, checked by a keyboard input, or set programmatically somewhere else in the app?

I have a CheckBox that should fire a certain set of other things, but only when it’s been clicked by a mouse (or un-checked by a keyboard input, somehow). However, if another set of events in the program causes that CheckBox to be un-checked (Say, a
CheckBox being un-checked), then I don’t want that first CheckBox’s set of things to activate.

I know this might sound a bit confusing, so if you need a visual element for further clarification, please let me know. :~) Thanks!