Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Okay, here's what I want to do - when the player is at the main menu, I want them to be able to type in cheat codes. That's the only place I want it to work. I don't want to give them a text box to type into. Rather, I want them to simply type in a word (let's say "cheat", just for simplicity sake) that activates the cheat code. I only need to capture keyboard input when the window is in focus. What can I do to accomplish this?

share|improve this question
Could you please provide additional info, which part of this task seems difficult to you? What have you tried so far? – Petr Abdulin Aug 27 '12 at 9:38
up vote 3 down vote accepted

You know your keywords. So store those in a string array. Store every key press into a char array and read the sequence. Allow a time out that clears the array. Compare your char string to any of the cheat keywords. When a match is found you call your cheat function.
your game should have states ( like MENU,INGAME, whatever) it's simple a matter of "if" menu is active.

share|improve this answer

Given the complete lack of implementation details provided, I'd simply say that you get the keyboard state just like you would during your normal game play, you remember which keys were pressed in order, and if the player is in the menu and a cheat code is recognized, you do stuff.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.