The short answer is that a sensor in the tip of the gun registers the proper amount of light on the screen when the gun is pointed at a duck, and the wrong amount of light when it isn't.
The Straight Dope covered this a few years ago. Here's a link to their more complete explanation: http://www.straightdope.com/columns/010511.html.