Sensor to distinguish between different types of pegs on a pegboard
Use a multi-pole jack plug.

Figure 1. Random 4-pole, 3.5 mm jack plugs from Wish.com.



simulate this circuit &ndash; Schematic created using CircuitLab
Figure 2. Plugs can be encoded by shorting out the tip, ring 1, ring 2 to sleeve pins in a binary code pattern.
You can't use code 0 as this will be the same as no plug inserted. That leaves you with seven possibilities and you only need four. Colour-coding the plugs to indicate their numerical value seems a good idea to me.



simulate this circuit
Figure 3. Preventing cross-feeds. 1N4148 diodes should be small enough to fit two into a plug.
As pointed out by @A.I.Breveleri the addition of diodes in the plug allows the use of a keyboard scanning solution. In this type of arrangement the diodes prevent cross-feeds when multiple keys are pressed. The same arrangement would work here.

Figure 4. Keyboard matrix example. Image source: Gammon.com.
See the linked article for an explanation.