🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #382

Re: How do I recognize arrow keys with getch() in C?

#382
From: Ron Dippold
Date: Tue, 11 Aug 1992 19:01
28 lines
1434 bytes
thesame@engin.umich.edu (Stephen Su) writes:
>I am using Borland C++ to try and write a simple text viewer and would like
>to use the up and down arrow keys and the PgUp/PgDn/Home/End keys for various
>operations.  How can I recognize the keys with getch(), or am I on the wrong
>track?

When you use an extended key, such as the Fx keys, etc., you will get
back first a 0 and then the extended code.  I'm not sure how Borland
does it, but I can't think it would be too differently.

Thus, you'd do this:

	switch( c=getch()) {
		case 'a': blah blah blah blah break;
		etc.
		case ' ': blah blah blah blah break;
		case 0:
			switch( c=getch()) {
				case 72: blah blah blah break;
				etc.
			}
		break;
	}

There are tables of what the extended key codes are, or you can just
experiment. 
-- 
The shortest distance between two points is through hell.  -- Brian Clark
Technical Details
Message-ID: <rdippold.713559703@cancun>
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sun-barr!ames!pasteur!dog.ee.lbl.gov!network.ucsd.edu!qualcom.qualcomm.com!cancun!rdippold
References: <S9a-CYB@engin.umich.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!sun-barr!ames!pasteur!dog.ee.lbl.gov!network.ucsd.edu!qualcom.qualcomm.com!cancun!rdippold
From: rdippold@cancun.qualcomm.com (Ron Dippold)
Subject: Re: How do I recognize arrow keys with getch() in C?
Message-ID: <rdippold.713559703@cancun>
Sender: news@qualcomm.com
Nntp-Posting-Host: cancun.qualcomm.com
Organization: Qualcomm, Inc., San Diego, CA
References: <S9a-CYB@engin.umich.edu>
Distribution: usa
Date: Tue, 11 Aug 1992 19:01:43 GMT
Lines: 28