Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

ASCII codes for arrow keys

ascii

  • Please log in to reply
2 replies to this topic

#1 DarkLordCthulhu

DarkLordCthulhu

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 422 posts
  • Location:The bash shell
  • Programming Language:C, JavaScript, Bash, Others
  • Learning:Ruby, Others

Posted 10 October 2011 - 12:44 PM

I've noticed that the arrow keys have the ASCII codes 65, 66, 67, and 68, the same codes as A, B, C, and D. I want to write a program that can detect the arrow keys in POSIX noncanonical mode. How can a C program tell whether a key entered is an arrow key or one of the letters?
  • 0
Programming is a journey, not a destination.

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 10 October 2011 - 12:48 PM

When I was detecting arrow keys in Turbo-Pascal, arrow keys were actually TWO ASCII characters. There was an escape character (I think), then the corresponding letter.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 DarkLordCthulhu

DarkLordCthulhu

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 422 posts
  • Location:The bash shell
  • Programming Language:C, JavaScript, Bash, Others
  • Learning:Ruby, Others

Posted 10 October 2011 - 02:47 PM

So I suppose I should use wide characters then?

EDIT: Seems to work. I just tested it and the sequence is apparently 27-91-* for the arrow keys. I managed to detect them by just using getchar() three times.
  • 0
Programming is a journey, not a destination.





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download