-
Hiding Input
I was wondering if anyone knew of a way to hide the input when the user enters it, such as when you enter a password on the internet, and the stars appear instead of the keys you are typing. In a (rather simple) game program that I was writing, (somewhat similiar to Rock Paper Scissors you could say), player one would enter his/her play, and that play would be shown on the screen when he/she typed it in (it was not being couted, just being shown on the screen when entered), and as of such, player two would have an unfair advantage when playing and choosing their own play. So, does anyone have a way in C++ Programming that one could hide input in the above needed way? Thanks!
-
I'm sure theres functions for this but all I can think of now is to use gecth() followed by a backspace (\b I think), then cout a *.
But as I said theres must be a way to hide it.
OR You could set the input color to black
Code:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0000);
Which I did not test but I'm pretty sure its right. This will set all following output to black text, so switch back to normal with
Code:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0007);
edit: FYI You'll need to #include <windows.h>
~ Paul
-
changing the colour to black is not safe enough, all the user has to do it change the bg colour of the console window in order to see the text
-
Then wont the other player know that they're cheating if they see them doing that?
-
I actually just tried it and you cannot see what the text says by changing the background colour of the console because the code I gave sets the backround as well as foreground colours, so on a pink background (what i set) the part where the text goes has a black bacground as well as text.
So the code example I gave should work fine.
~ Paul