To prevent a key inserted into a switch body from slipping off undesirably by play of the door, etc., in a key switch suitable for turning-on and turning off power for a machine tool according to the detection of open and close of the entrance door of a fence surrounding the automated machine tool, etc.
A plugging body 22 has a rod plugging part 20 integral with the key 4. A rubber holder 22 having a holding groove 24 into which the plugging part 20 is inserted into and out is provided integrally with the switch body 1. When the key 4 is inserted into the switch body 1, the plugging part 20 is taken in a containing part beyond a narrow groove part of the holding groove 24 which holds the plugging part 20 by the predetermined holding force, to prevent it from slipping off.