Problem with getche()

This is a discussion on Problem with getche() within the C++ Programming forums, part of the General Programming Boards category; For some reason my first post was empty. Anyway, I'm having a problem with getche() and GetAsyncKeyState(). I use getche() ...

  1. #1
    Registered User Caze's Avatar
    Join Date
    Nov 2002
    Posts
    18

    Angry Problem with getche()

    For some reason my first post was empty.

    Anyway, I'm having a problem with getche() and GetAsyncKeyState(). I use getche() to store the pressed key in a string and use GetAsyncKeyState() to check what key I pressed. But when I press one of the arrow keys, it adds two characters to the string (ZERO character and P if I pressed down) even when .length() says it added just one. When I then try to remove those characters from the string with .erase() I can only get rid of the ZERO character. When I then print the string the second character is always there messing things up.

    I've even tried to do the checking first and adding the key to the string afterwards if none of the arrows was pressed but it's still there haunting.

    Is there a way to get rid of that second character? Or is there another way to save the pressed key to a string than getch()/getche()?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    It sounds like you're having problems with the extended character codes. Check the FAQ for possible solutions.
    My best code is written with the delete key.

  3. #3
    Registered User Caze's Avatar
    Join Date
    Nov 2002
    Posts
    18
    I checked the FAQ again but there is nothing there that can help me. As far as I know, GetAsyncKeyState() is the only way to check if one of the numpad keys was pressed and I need to use those keys for other things.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with fgets....
    By Huskar in forum C Programming
    Replies: 5
    Last Post: 03-29-2009, 10:13 AM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21