×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ALT Key

ALT Key

(OP)
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.

RE: ALT Key

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( "Alt key was pressed" );
  }
  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
"Alt key was pressed".

Hee S. Chung
heesc@netian.com
http://www.netian.com/~heesc

RE: ALT Key

(OP)
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

RE: ALT Key

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
http://www.netian.com/~heesc

RE: ALT Key

(OP)
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 ;-)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close