Oops never mind, don't use my code, use the one you found...
Change this part so that it only happens with a key press.