The figure shows a slot cut into a shaft. The shaft is supported on the left by bearings. A shear key of specified length and width is shown on the top right.
 

A small square length of metal called a shear key is used to keep the gear from rotating relative to the shaft.