Thread: Hiding Input

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    1

    Question 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!

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    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
    Last edited by nickname_changed; 03-06-2003 at 02:18 AM.

  3. #3
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    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

  4. #4
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Then wont the other player know that they're cheating if they see them doing that?

  5. #5
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 01:59 AM
  2. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Help with Input Checking
    By Derek in forum C Programming
    Replies: 7
    Last Post: 06-17-2003, 03:07 AM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM