Is there a way to add an observer or something in order to know when the user has selected a different photo from within the library module? Essentially I want a function to be called when the user changes the selected photo within the library.
You could try the undocumented LrApplication.addActivePhotoChangeObserver. Its signature may be similar to LrDevelopController.addAdjustmentChangeObserver. Make sure you're trapping all errors or using a debugger while you're experimenting with it.
I vaguely recall trying it out a couple years ago and deciding not to use it, but I can't remember why. I have an even vaguer memory that Rob Cole may have noticed that some changes in selection weren't getting reported.
A couple of my plugins poll every quarter of a second or so for changes to module and selection. It offends the more delicate architectural sensibilities, but it works well without imposing a noticeable CPU cost.
I implemented the LrApplication.addActivePhotoChangeObserver function. So far I have not noticed any adverse side effects, it's working for me as expected. I'll keep an eye out for anything weird as its undocumented. Thanks!