That looks like a quadrature type from a mouse. If so, the 2 pins are the LED and the 3 pins are 2 phototransistors. Probably +5 V to the center one and outputs from the other 2.
ClydeCrashKop seems right.Although the image is not that much clear but this seems like an optocoupler.This may have either 4 or 5 leads.2 for IR LED (or say IRED) and 2 or 3 for photo transistor.Base lead may or may not be included in the package.for example H21A1 is the type of optocoupler in which base lead is not included.See the data sheet and it just look like your sensor i think.View attachment H21A1.pdf