Take a look at the state change detection example and the state change for active low switches tutorials. They will allow you to detect when the switch becomes pressed (the transition) as opposed to when it is pressed (the level).
Read the forum guidelines. Post your test code in code tags. Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) to indent the code for readability before posting code.