Thread: How to make pressing a button do something?

  1. #1
    Registered User
    Join Date
    Oct 2009

    How to make pressing a button do something?

    Hi, I want to write code so that pressing a specified button, at any time, will run some function. I don't really have an idea of how to do this. Can anyone point me in some direction? To give more information of what I want - I am trying to write code for a irobot create to stop driving when I hit a button. I need the button press function to happen even if the program is in an infinite while loop. Any help is appreciated.

  2. #2
    Registered User xentaka's Avatar
    Join Date
    May 2011
    EDIT: NM thought you were talking about a GUI button until I reread that.

    Might be something like

    Running in its own thread maybe... sure experts can shed some light on it.
    Last edited by xentaka; 05-22-2011 at 06:15 PM.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    United States
    I'd read this for starters: FAQ > How can I get input without having the user hit [Enter]?

    This is the answer because as soon as the user presses the key you want, (instead of '\b') you can call the function. If you want to do this all the time, then I'd wager that your program needs an event driven loop: a loop that continuously waits for specific inputs in order to trigger events. Events can be handled by objects or functions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. screen color detection and button pressing
    By cwn11 in forum C Programming
    Replies: 1
    Last Post: 11-23-2008, 10:39 PM
  2. Virtually pressing a button
    By Queatrix in forum Windows Programming
    Replies: 4
    Last Post: 08-19-2005, 10:19 AM
  3. Pressing a button works sometimes
    By johny145 in forum Windows Programming
    Replies: 14
    Last Post: 05-18-2005, 11:53 AM
  4. Pressing A Button on Dos..
    By yakabod in forum A Brief History of
    Replies: 8
    Last Post: 01-30-2003, 07:46 AM
  5. Pressing a button in another app
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 03-11-2002, 12:53 PM