Sounds like you're looking at a detection of the change of state; have a look at the state change detection example that comes with the IDE.
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project
See About the Installation & Troubleshooting category.