Have you looked at the Button example in the IDE ? It shows how to read the state of an input and act on that state