25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more...
Home   Projects   Up   Sitemap   Search   Blog   Forum+Chat   About Us   Privacy   Terms of Use   Feedback   FAQ   Images   Services   Ads   Donate   Humor

Keycodes.cpp

Reports the key code generated when you press a key.

/*	keycodes.cpp			3-10-96
	Copyright (C)1996, 2006 Steven Whitney.
	Published under GNU GPL (General Public License) Version 2, with ABSOLUTELY NO WARRANTY.

	Borland C++ 4.0 for MSDOS.
	Shows values from keyboard keystrokes.
	A run of the program shows that getch() does not interpret function
	keys, nor even acknowledge them as keystrokes. Neither does kbhit().

	To use function, altkeys, etc., use ci(), which now handles them all
	correctly.  AND use csts() instead of kbhit().

*/
#include "c:\bcs\my.h"
#pragma hdrstop

#include "c:\bcs\mylib.cpp"

//////////////////////////////////////////////////////////////////////////////
int main()
{
int ch = 0, highbyte, lowbyte;
while(1)
	if(csts())
	{
		ch = ci();
		if(ch == 3)
			cout << "control-c pressed" << endl;
		if(ch == 0x3b00)
			cout << "F1 pressed" << endl;
		highbyte = (ch & 0xff00) >> 8;
		lowbyte = ch & 0xff;
		cout << (char)ch << " = (high)" << highbyte << " (low)" << lowbyte
			 << " = " << hex << setw(4) << setfill('0') << ch << dec << endl;
		if((ch == 3) || (ch == 27))   	// ^C or ESC quits program
			return(0);
	}
}			// end main

 

 

Valid HTML 4.01 Transitional Valid CSS
View content labeling at ICRA.
Copyright ©2008 Steven Whitney. Last modified 02/27/2008.