Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture stdin input without echoing characters to screen

Tags:

c++

stdin

qt

I have a very simple code:

char character;    
std::cin >> character;

However, I would like it to behave as follow:

  1. Don't echo to console the character I type
  2. std::cin should return (unblock) right away when a character is pressed without having to press the Enter key

Is this possible? I also have access to Qt.

like image 410
sivabudh Avatar asked Dec 28 '25 16:12

sivabudh


1 Answers

This is going to be platform dependent, but you can use

getch() which is part of conio.h if you're on windows

or

getch() as part of curses.h if you're on *nix

References

  • http://opengroup.org/onlinepubs/007908799/xcurses/curses.h.html
  • http://en.wikipedia.org/wiki/Conio.h
like image 159
Jamie Wong Avatar answered Dec 30 '25 04:12

Jamie Wong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!