Reputation: 2694
I'm trying to build a simple form in a c++ win32 console application. instead of using cin and keep prompting the user to enter the details, i would like to display the form labels then using the tab key, allow the user to tab through.
What is the simplest way of doing this, without having to use ncurses?
all I need is cout the below all at once:
Name:
Username:
Email:
set the cursor position next to name Field, then each time you hit tab, i gotoxy, and set the cursor at the next position, then set the the cin to the next variable eg. at startup
gotoxy(nameX, nameY);
cin >> name;
Hit Tab/enter
gotoxy(usernameX, usernameY);
cin >> username;
Hit Tab/enter
gotoxy(emailX, emailY);
cin >> email;
is this even doable?
I tried while loops with, GetAsyncKeyState, and keyboard events, but the cin is not working properly in that loop.
is there any good example for a super simple form, or reference for doing that? I know how to SetConsoleCursorPosition, but how to implement the tabbing while still being able to capture cin?
thanks
Upvotes: 3
Views: 1155
Reputation: 7137
What is the simplest way of doing this, without having to use ncurses?
Using ncurses (or an equivalent library) is the simple way to do this, by far.
You seem to forget that tab is just another character when reading by lines (as in cin>>name;
). To emulate ncurses, your program would need to handle multiple classes of key strokes (backspace, tab, arrows, characters, digits, even function keys, etc.), do whatever is appropriate, properly maintain the state of the screen, and the position of the cursor -- all to read three text fields from the user.
Consider spending a few hours perusing the source code, even if you don't use it you might learn quite a lot (that's a serious suggestion, BTW).
Upvotes: 3