2

Since spaces break string inputs, I was wondering how to make a dash appear when you hit space in real-time in cmd. This is what I'm working with so far:

if (GetKeyState(VK_SPACE) & 0x20)
                {
                    //insert a '-'
                }
cin >> name;

By the way, I know that this method is only available for Windows, but this whole project is just a small cmd game to get comfortable with C++ so I'm not intending on it being portable.

  • 1
    Just read your input with `std::getline`, it doesn't stop on spaces. – Igor Tandetnik May 23 '20 at 19:54
  • For whatever reason, when I use `getline`, it completely skips over cin and just outputs the cout that I have assigned to show after you input a name –  May 23 '20 at 20:15
  • 1
    My crystal ball points me to https://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction – Igor Tandetnik May 23 '20 at 20:16
  • Sorry, though this is close to my problem, it completely skips over my ability to input, not just ignoring what I input. –  May 23 '20 at 23:25
  • Immediately skipping all attempts at input is precisely the symptom of the issue I pointed you to. – Igor Tandetnik May 23 '20 at 23:29

1 Answers1

0

I think you can try this:

if (GetKeyState(VK_SPACE) & 0x20)
                {
                    keybd_event(VK_SUBSTRACT,0x45,0,0); // send the input for -
                }
CanciuCostin
  • 1,337
  • 1
  • 7
  • 24