This forum is in archive mode. You will not be able to post new content.

Author Topic: Taking multiple input from the user on console?  (Read 1954 times)

0 Members and 1 Guest are viewing this topic.

Offline PsychoRebellious

  • Peasant
  • *
  • Posts: 130
  • Cookies: -6
    • View Profile
    • My Rantings
Taking multiple input from the user on console?
« on: March 05, 2015, 10:08:42 PM »
I was shoulder surfing this guy working at the bank, the software that they were using was some console based so-not-fancy one. From that he was editing the credits or transfers. Anyway it was a console input with something like the following

id:
transaction:
deposit:
withdraw:


(He was using tabs to direct the cursor to the next field)
Something like the above. I am wondering if taking multiple input like that is possible with C++, and if so how? Usually console based programming goes like this
enter username: *presses enter*
*enter password pops up*

It would be more convenient to do just this
enter username:*write here then press tab*
enter password: *fill this too and press enter*

Both value to the input stream. It was almost like form fields, and it would be so more convenient to do that. For the time being, I am mirroring a console based ATM machine like program, and there it asks for username and THEN password, however It would be more convenient if it was to take multiple input and send them all to the input stream at once. What are my options with this? I've googled already, most results that come up are not what I'm looking for

Offline ArkPhaze

  • Peasant
  • *
  • Posts: 136
  • Cookies: 20
  • null terminated
    • View Profile
Re: Taking multiple input from the user on console?
« Reply #1 on: March 06, 2015, 06:45:22 AM »
Yes. Use console buffers (I'm assuming you're using Windows), and set/manipulate the caret position before grabbing input (as normal). Of course, you should have written all of the input text out to stdout beforehand. Setting the caret position just places the caret at a convenient location to avoid writing over the existing buffer that relates to the fields of text that you are providing the input for (as the user). It's actually really easy..
sig=: ArkPhaze

[ J/ASM/.NET/C/C++ - Software Engineer ]

Offline PsychoRebellious

  • Peasant
  • *
  • Posts: 130
  • Cookies: -6
    • View Profile
    • My Rantings
Re: Taking multiple input from the user on console?
« Reply #2 on: March 06, 2015, 07:42:00 AM »
Yes. Use console buffers (I'm assuming you're using Windows), and set/manipulate the caret position before grabbing input (as normal). Of course, you should have written all of the input text out to stdout beforehand. Setting the caret position just places the caret at a convenient location to avoid writing over the existing buffer that relates to the fields of text that you are providing the input for (as the user). It's actually really easy..

I'm on a linux platform. However, I am not getting the idea of manipulating the caret position.

Offline ArkPhaze

  • Peasant
  • *
  • Posts: 136
  • Cookies: 20
  • null terminated
    • View Profile
Re: Taking multiple input from the user on console?
« Reply #3 on: March 07, 2015, 07:28:40 PM »
Then you can use something like:
Code: [Select]
Display *dpy;
Window root_window;

dpy = XOpenDisplay(0);
root_window = XRootWindow(dpy, 0);
XSelectInput(dpy, root_window, KeyReleaseMask);
XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, 100, 100);
XFlush(dpy); // Flushes the output buffer, therefore updates the cursor's position.

http://stackoverflow.com/questions/2433447/how-to-set-mouse-cursor-position-in-c-on-linux


Note: You have to link with the X11 lib, on GCC "-lX11"
sig=: ArkPhaze

[ J/ASM/.NET/C/C++ - Software Engineer ]

Offline KryDos

  • Serf
  • *
  • Posts: 42
  • Cookies: 8
  • Software Engineer, Emacs uesr
    • View Profile
Re: Taking multiple input from the user on console?
« Reply #4 on: March 07, 2015, 07:41:35 PM »
You can try to use ncurses. This lib was developed to create programs with terminal based interface.

This lib also allows you to create many input fields and then you can grab the data from these inputs (similar to GUI applications)
« Last Edit: March 07, 2015, 07:42:58 PM by KryDos »

Offline PsychoRebellious

  • Peasant
  • *
  • Posts: 130
  • Cookies: -6
    • View Profile
    • My Rantings
Re: Taking multiple input from the user on console?
« Reply #5 on: March 07, 2015, 08:05:06 PM »
You can try to use ncurses. This lib was developed to create programs with terminal based interface.

This lib also allows you to create many input fields and then you can grab the data from these inputs (similar to GUI applications)
This is exactly what I was wondering. Moving the cursor was just part of it, but grabbing the data from there like a form field was what I wanted to do. Ill give this a go

Offline ArkPhaze

  • Peasant
  • *
  • Posts: 136
  • Cookies: 20
  • null terminated
    • View Profile
Re: Taking multiple input from the user on console?
« Reply #6 on: March 08, 2015, 08:40:07 AM »
This is exactly what I was wondering. Moving the cursor was just part of it, but grabbing the data from there like a form field was what I wanted to do. Ill give this a go

Input is always going to be the same. Why would it be any different just because you can move the cursor around. You should NOT be trying to parse the data from the console buffer after the fact, but rather, when the input is typed in.
sig=: ArkPhaze

[ J/ASM/.NET/C/C++ - Software Engineer ]

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.