An optical sensor for an image forming apparatus, comprising: light-emitting means arranged to emit light toward a target in the image forming apparatus, wherein the target is configured to move in a first direction; first light-receiving means that includes a plurality of first light-receiving elements arranged along the first direction, and is arranged so as to receive light emitted from the light-emitting means and specularly reflected off the target; second light-receiving means arranged on a different position from the first light-receiving means in a second direction different from the first direction, and that includes a plurality of second light-receiving elements arranged along the first direction, and is arranged so as to receive light emitted from the light-emitting means and scatter reflected off the target, aperture stop member (71, 75) arranged to limit a size of reflected light that is incident on the first light-receiving means and the second light-receiving means, in the first direction; selection means arranged to select whether or not each of the plurality of first light-receiving elements in the first light-receiving means is a first effective light-receiving element and to select whether or not each of the plurality of second light-receiving elements in the second light-receiving means is a second effective light-receiving element; generation means arranged to generate a first detection signal from an output of the first effective light-receiving element selected by the selection means, and to generate a second detection signal from an output of the second effective light-receiving element selected by the selection means; and output means arranged to output the first detection signal and the second detection signal. light-emitting means arranged to emit light toward a target in the image forming apparatus, wherein the target is configured to move in a first direction; first light-receiving means that includes a plurality of first light-receiving elements arranged along the first direction, and is arranged so as to receive light emitted from the light-emitting means and specularly reflected off the target; second light-receiving means arranged on a different position from the first light-receiving means in a second direction different from the first direction, and that includes a plurality of second light-receiving elements arranged along the first direction, and is arranged so as to receive light emitted from the light-emitting means and scatter reflected off the target, aperture stop member (71, 75) arranged to limit a size of reflected light that is incident on the first light-receiving means and the second light-receiving means, in the first direction; selection means arranged to select whether or not each of the plurality of first light-receiving elements in the first light-receiving means is a first effective light-receiving element and to select whether or not each of the plurality of second light-receiving elements in the second light-receiving means is a second effective light-receiving element; generation means arranged to generate a first detection signal from an output of the first effective light-receiving element selected by the selection means, and to generate a second detection signal from an output of the second effective light-receiving element selected by the selection means; and output means arranged to output the first detection signal and the second detection signal.