Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ALT Key 1

Status
Not open for further replies.

xGrob

Programmer
Jun 6, 2001
36
CA
How do you detect keystrokes from a keyboard in DOS
-WITHOUT- using getch(). I am specifically trying to detect when the ALT Key is depressed, NOT an ALT+* event.
 
You can read ROM bios data address :

#include <stdio.h>
#include <conio.h>

#define KEY_ADDRESS 0x417 /* ROM BIOS data address */
#define KEY_RSHIFT 0x01
#define KEY_LSHIFT 0x02
#define KEY_CTRL 0x04
#define KEY_ALT 0x08
#define KEY_SCROLL 0x10
#define KEY_NUMLOCK 0x20
#define KEY_CAPSLOCK 0x40
#define KEY_INS 0x80


int main( void )
{
getch();

if( *((char*)KEY_ADDRESS) & KEY_ALT ) {
puts( &quot;Alt key was pressed&quot; );
}
return 0;
}

Compile and execute this program. And then it waits
a key input and you can press alt key at that time.
Hold the alt key and now press any key ( if you
use a dos console on Windows, esc, enter, space, ...
keys can give the special meaning to Windows so use
an alphabet or a digit key for this case. )
to return the 'getch' function. If this program
works fine for you, you can see the message
&quot;Alt key was pressed&quot;.
Hee S. Chung
heesc@netian.com
 
thanks anyway but that's no good, i want to capture the ALT without having to press another key.. eg: press ALT and a pop-up menu opens
 
You can detect whether ALT key is pressed or not
by using my source code. Surely you can capture
ALT without having to press another key. The
reason why I commented to use some other keys
is that, you need to confirm my source can
detect that ALT key is pressed.

As I mentioned it is very simple and fast
to detect ALT key is pressed.

if( *((char*)KEY_ADDRESS) & KEY_ALT ) {
/* alt key is pressed now */
}

KET_ADDRESS and KEY_ALT are defined in the
source which I previously supplied.

Above code is not related to other keys -
it just detect ALT key status.

Thanks.
Hee S. Chung
heesc@netian.com
 
dammit, you're right.. i just didn't try to implememt it it any other way

by doing:

while(1) {
sleep(1);
if( *((char*)KEY_ADDRESS) & KEY_ALT ) {
//bla
}
}

it clearly does work, thanks alot ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top