The light gun technology is as old as gaming consoles themselves. Magnavox Odyssey (1972) already had a gun as an optional controller. It was often used with pong clones and later with many other consoles. As long as CRT TVs were in use, so were the light guns. The last consoles having light guns were Sega Saturn, Sony PlayStation 2, Sega Dreamcast and the first Xbox.
The light gun’s principle of operation is simple - it reacts to the light of the TV display. In its simpler form (pongs, NES), its sensor needs to be pointed at a large white square on screen. Later models had photo receivers sensitive enough to detect the position of the electron beam drawing a picture on the kinescope. What does it mean? It means that unlike today's solutions - these were very accurate devices.