Mosfet on/off with delay
Try using an EXOR gate with an RC to generate a pulse of limited duration when a switch opens or closes: -



The output pulse width is roughly equal to about R x C in time. It will produce a pulse when an edge is detected within tens of nano seconds (or less) and when the capacitor eventually charges, the pulse output will reset.

When the input changes state another pulse will be generated.