Important alert: (current site time 7/15/2013 4:59:47 PM EDT)
 

VB icon

[Detecting Dos Arrow Keys]

Email
Submitted on: 12/6/2002 11:12:56 PM
By: Josh Nixon  
Level: Beginner
User Rating: By 9 Users
Compatibility: C++ (general)
Views: 17288
author picture
(About the author)
 
     This will just show how a person might use the arrow keys in DOS.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :[Detecting Dos Arrow Keys]
//**************************************
#include <iostream.h> //cout
#include <conio.h> //kbhit() getch()
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: [Detecting Dos Arrow Keys]
// Description:This will just show how a person might use the arrow keys in DOS.
// By: Josh Nixon
//
// Assumes:This will just show how a person might use the arrow keys in DOS.
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=5339&lngWId=3//for details.//**************************************

#include <iostream.h>
#include <conio.h> //kbhit() getch()
//Getch()= retrieves the char and wait for it to be pressed
//kbhit() = keeps processing commands while you hit
//These are used for arrow keys since getch() does not return extended char
const char CPPKEYUP = 72;
const char CPPKEYLEFT = 75;
const char CPPKEYRIGHT = 77;
const char CPPKEYDOWN = 80;
int main()
{
 char Arrow = 0;
 Arrow = kbhit();
 while(Arrow !=27)
{
Arrow = getch();
 switch(Arrow)
 {
case CPPKEYUP:
cout<<" UP "
break; 
case CPPKEYDOWN:
cout<<" DOWN "
break;
case CPPKEYLEFT:
cout<<" LEFT "
 break;
 case CPPKEYRIGHT:
cout<<" RIGHT "
 break;
 }
}
return 0;
}


Other 35 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
12/19/2002 10:06:27 PMMike Nolan

Very cool!
(If this comment was disrespectful, please report it.)

 
12/26/2002 2:45:37 PM

your codes are very good
thanks
(If this comment was disrespectful, please report it.)

 
4/17/2003 1:19:43 AMDarkMercenary44

Thanks alot, just start C++ and I'm making a graphical menu, and this helped out alot...
(If this comment was disrespectful, please report it.)

 
5/18/2003 5:40:19 PM

I'm making a dos game where I needed the arrow keys and this helped greatly! Awesome example! You forgot the semi-colons after the cout's but that's no biggy. Thumbs up!
(If this comment was disrespectful, please report it.)

 
6/23/2003 12:34:16 AM

umm, when i compile it on my compiler, it gives me 2 errors:
implicit declaration of function 'intkbhit(...)'
-------
implicit declaration of
function 'int getchar(...)'

im a newb at this so, i dont know what any of this means... (i copy pasted exactly from here, only thing i did was add ; to end of cout's. Help would be much appreciated.
e-mail= the_center_68@yahoo.com
(If this comment was disrespectful, please report it.)

 
7/12/2003 7:46:38 AMEric Camadine

Well if you're using Dev-C++, their library on the kbhit function is incomplete. I suggest you download a dos compiler for this one, or ask me to e-mail you one.
(If this comment was disrespectful, please report it.)

 
10/8/2004 10:56:09 PMLkNsngth

Suggestion: Put SystemCLS after everything Thatway, it clears when arrow keys are pressed
(If this comment was disrespectful, please report it.)

 
11/1/2005 10:58:43 PMchrzoc

use system("cls");
to clear the screen after the function is parsed
(If this comment was disrespectful, please report it.)

 
11/1/2005 11:01:12 PMchrzoc

also in msvc++ make sure you add ';' after the codebreaks (break;)
(If this comment was disrespectful, please report it.)

 
9/25/2006 4:59:15 PMbucky23

Very nice code, I've been trying to do this for a long time, but I never knew about kbhit(). Good job.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.