Link to home
Start Free TrialLog in
Avatar of jim_pugh
jim_pugh

asked on

VIsual Studio 2005 C++ arrowkey capture, help me make more progress in my console wordprocessor

I use Visual Studio 2005 and I have have trouble capturing the arrow keys on my console word processor project.  I got a far a capturing them but when I press shift + H it thinks I am pressing the up key.  Why when the up key is clearly \0H  (null H)  and not shift H> wierd.  Maybe I need to use a string and not a char to store the keypresses.

Here a code fragment:

if (_kbhit())
{

      keyPress = _getch();
      if (keyPress != '\0')
      {

            if (keyPress >= 32 && keyPress <= 127)
            {                  
                  if (keyPress == '\0H') //up key pressed
                  {
                        if (arrayIndex != 0) // if not a TOP
                        {
                        y--; arrayIndex--;
                        if (x > m.len(line,arrayIndex) + (boxX +1))
                        {
                                                      
                        x = (m.len(line,arrayIndex) + (boxX +1));
                        stringIndex = m.len(line,arrayIndex);
                        }
                              m.gotoxy(x,y);
                        }
                  }
                  else if (keyPress == '\0P') //down
                  {
                                          
                  }
                  else if (keyPress == '\0M') //right
                  {
                                          
                  }
                  else if (keyPress == '\0K') //left
                  {
                                          
                  }
                  else // not an arrow key (implmented) of function key (not implmented yet)
ASKER CERTIFIED SOLUTION
Avatar of Jase-Coder
Jase-Coder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jim_pugh
jim_pugh

ASKER

Cheers mate.  That link sorted me out.  It is best to capture the key press as an int that stores is ASCII value rather than a char that stores the letter.  Then when I cout the int, I just do it likes this
cout << char(int) ;
rather than cout << char;
and save it to my array the same way.