In WP7, you can do this by using Assembly.Load to access Microsoft's unsupported (internal-use-only) "Microsoft.Phone.Media.Extended" DLL and then use reflection to access the camera and handle the shutter pressed events. Unfortunately, this DLL doesn't exist in WP8 and has been replaced by other media APIs, which strip away some of the complexity of that assembly (no reflection needed), but also some of its key features (e.g. being able to use the camera button under lockscreen).
In WP8, you can use AudioVideoCaptureDevice.OpenAsync to get access to the camera device, but the camera button events have been moved to a static class called CameraButtons. You can use those events to override the behavior of the camera buttons in an app. Learn more about them here:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202963(v=vs.105).aspx