A technique often used in software engineering is :
when a key is pressed, check a variable and toggle it