For home work i have to do SMS in c++ ,which has to be exactly like on mobile.I dont know how to do this.

Dani AI

Generated

A concise how-to that fills the gaps in 's reply and gives practical, platform-aware steps for building a phone-style multi-tap input in C++ (useful for the homework described).

Start with the input layer: a console program must read raw key events, not line-buffered input. On POSIX (Linux/macOS) disable canonical mode with termios and either use select/poll or make stdin non-blocking so you can wait with a timeout. On Windows a quick prototype can use _kbhit()/_getch() from <conio.h>, while a robust solution uses the Console API (ReadConsoleInput / SetConsoleMode). For cross-platform terminal work, ncurses (or PDCurses on Windows) removes most portability headaches; for a GUI, use Qt or SDL.

Implement a small state machine for multi-tap behavior (no code shown here so you can adapt to your style): keep a mapping table for each digit, a variable for the last key pressed, an index into that digit's letters, and a monotonic timestamp of the last event. On each key event either cycle the index (if same key and elapsed < timeout) or commit the pending character and start a new cycle. Commit also happens when the timeout expires or when a different key is pressed. Make the timeout configurable (typical start ~500–800 ms) and use steady/monotonic time to avoid clock jumps.

Practical tips and pitfalls: restore terminal settings on exit (use RAII), log key events while debugging, handle OS key auto-repeat by ignoring extremely short intervals, and treat multi-byte/UTF-8 carefully if you later add non-ASCII letters. Test sequences that mix quick repeats, alternating keys, backspaces, and Enter so the commit/replace rules behave intuitively.

Recommended Answers

All 3 Replies

What hardware are you supposed to use?

I must wrote just a program like on mobile keybord. When you press 1 will be on the screen a, when you press another time 1 you will get on screen b, etc.

You will have to do some console handling for that. At first glance the procedure will be something like below.

Press a key
  Look what the key is
  If another key is pressed within the given time limit
        If it was the same as the previous one
                  Erase first character and update buffer with the next one
        else 
                   Update buffer with the pressed key 
    Else
         Update the buffer with the pressed key

There is no portable way of getting it done, unless you do some serious console scrolling. So you may have to use either a 3rd party library or the API of the operating system you are using.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.