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   Payments   Humor   Music

Borland C++ MSDOS utility program reports the key code generated when you press a key

Keycodes.cpp displays the key code that is generated when you press a keyboard key.

/*	keycodes.cpp			3-10-96
	Copyright (C)1996, 2006 Steven Whitney.
	Published under GNU GPL (General Public License) Version 3, 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
Yahoo! Search
Search the web Search this site
View content labeling at ICRA.