Toggle switch simulate keypress

Hello! Im new to Arduino, so need some help. I want a toggle switch to simulate a keybress every time its switched on/off.


You mean, when the switch makes the transition ON to OFF, an arduino pin should change from low, to high, remain at high for say 500mS, then revert to low. Exactly the same happens on a transition from OFF to ON.
Is that it ?

If you want the keypress only when the switch goes from on to off (ie. the transition), The state change detection example in the IDE (File, Examples, Digital) will show you how. You may need to change the logic to reflect how your switch is wired. For the timing, the blink without delay example will show how to do non-blocking timing.