Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 175507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:42:40+00:00 2026-05-11T13:42:40+00:00

I’m writing a game and I’m wound up in needing a console for simple

  • 0

I’m writing a game and I’m wound up in needing a console for simple text input; filenames and simple values.

Using SDL, my console looks the following at it’s simplest:

class   Console { public:   typedef std::list<String> InputList;    enum  Result   {     NOTHING = 0,     ENTERED,     ESCAPED   };    static const String&  GetInput()  { return input; }    static Result Query(SDLKey lastKey)   {     if(lastResult == ENTERED || lastResult == ESCAPED)     {       input.clear();     }      switch (lastKey)     {     case    SDLK_a:     case    SDLK_b:     case    SDLK_c:     case    SDLK_d:     case    SDLK_e:     case    SDLK_f:     case    SDLK_g:     case    SDLK_h:     case    SDLK_i:     case    SDLK_j:     case    SDLK_k:     case    SDLK_l:     case    SDLK_m:     case    SDLK_n:     case    SDLK_o:     case    SDLK_p:     case    SDLK_q:     case    SDLK_r:     case    SDLK_s:     case    SDLK_t:     case    SDLK_u:     case    SDLK_v:     case    SDLK_w:     case    SDLK_x:     case    SDLK_y:     case    SDLK_z:     case    SDLK_0:     case    SDLK_1:     case    SDLK_2:     case    SDLK_3:     case    SDLK_4:     case    SDLK_5:     case    SDLK_6:     case    SDLK_7:     case    SDLK_8:     case    SDLK_9:     case    SDLK_SLASH:     case    SDLK_BACKSLASH:     case    SDLK_PERIOD:     case    SDLK_COMMA:     case    SDLK_SPACE:     case    SDLK_UNDERSCORE:     case    SDLK_MINUS:         input += static_cast<char> (lastKey);         lastResult = NOTHING;         break;     case    SDLK_RETURN:         lastResult = ENTERED;         break;     case    SDLK_ESCAPE:         lastResult = ESCAPED;         break;     }     return lastResult;   }  protected:   static Result lastResult;   static String input; }; 

This would be called from the application’s main event loop, if the console is active and the last event was a keypress, then the result of the input is processed at a state where it’s necessary.

Of course, it looks incredibly awkward… What’s a better way to implement a simple console that can be easily rendered in my game’s window? (Not going anywhere near to highly unportable solutions like having to reroute std::cout or writing code to bring up a UNIX console etc.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:42:41+00:00Added an answer on May 11, 2026 at 1:42 pm

    One suggestion I would offer is to use if statements instead of a switch in this case:

    if(lastKey == SDLK_RETURN)     lastResult = ENTERED; else if(lastKey == SDLK_ESCAPE)     lastResult = ESCAPED; else if(lastKey >= SDLK_SPACE && lastKey <= SDLK_z) {     input += static_cast<char> (lastKey);     lastResult = NOTHING; } 

    I took some liberties and included some characters that you didn’t have in your code above, such as the ampersand, quotes, parentheses, brackets, etc. If you don’t want those keys, you can add a few more if statements to break it down a bit more.

    This assumes that the enum for the keys doesn’t change a lot. If it does change a lot you may be better off with what you had.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.