Thread: Getting user key presses

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    98

    Getting user key presses

    How can I get my program to react in a certain way depending on what key the user presses?
    For example, while the program is running, if the user presses F12, then it must show, for example, form2.

    How would I go about doing this?

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Take a look at the KeyDown, KeyPress, and KeyUp events.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    98
    I've tried that and it works, but how do I get it to check if I've pressed F12 or Enter?

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    I'm not sure what you're asking. Handle the KeyDown event and check the KeyCode property. I had no problem catching F12.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    98
    I found my problem! I was using keydata instead of keycode. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Window message loop (Keys)
    By Blackroot in forum Windows Programming
    Replies: 3
    Last Post: 09-12-2006, 05:15 PM
  2. Sifting through repeated key presses
    By Tronic in forum Windows Programming
    Replies: 2
    Last Post: 11-25-2004, 09:17 PM
  3. mkae it so when the user presses...
    By Rune Hunter in forum C++ Programming
    Replies: 10
    Last Post: 09-27-2004, 10:30 PM
  4. Key presses
    By Death_Wraith in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2004, 02:40 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM