A light gun is an input device used with arcade machines or consoles. Light guns have been available for almost all of the popular home consoles.

It's a plastic toy gun that you 'fire' at the screen. Games such as Virtua Cop, The House of the Dead, or, going way back, Duck Hunt let you to use the light gun to shoot the on-screen enemies (or helpless ducks).

How does it work?

There are two basic methods that a light-gun game can use to detect whether you were pointing it at the target when you pulled the trigger.

Method 1

When you pull the trigger, everything on the screen except the target briefly turns black, and the target lights up white. The light sensor on the end of the gun can detect if you're pointing at the white area, and registers a hit.

If there are various targets, the screen stays dark long enough to flash them all one after the other. The system can then tell which one (if any) was hit from the timing.

Method 2

This method is similar but a little more sophisticated.

Again, the gun has a light sensor on the end. This time though, when the gun is fired, the whole screen flashes white.

Now, we need to think for a second about how televisions work. To a human observer, a white television screen looks like a solid block of white. However, in reality, the picture is actually formed by the television's electron beam sweeping very quickly across the screen a few hundred times.

So, the player pulls the trigger, and the screen flashes white. Now, the gun's light sensor can detect the exact instant that the electron beam sweeps past the point on the screen that the gun is pointing at.

Since the computer system is also driving the television display, the system knows at what instant the electron beam started scanning across the display. So, it computes the difference in time between the electron beam starting its journey, and the electron beam hitting the part of the screen the gun is pointing at. From this, it can deduce what part of the screen the gun has targetted.

This method allows the game to determine exactly where the gun was pointed, allowing for a game with multiple targets. This was the method most commonly used up until a year or two ago.

The latest arcade light-gun games, e.g. Jurassic Park, use a refinement of this method so they don't need to flash the screen white. The gun is sensitive enough that it can detect the passing electron beam even if it isn't set to bright white. (There is a faint trace of the beam even on areas of the screen that appear black). Thus, they are able to keep a constant track of where the gun is pointed, as evidenced by the targetting crosshairs that are on screen at all times.

Cheers to TheBooBooKitty for some help with this.