?
Solved

Catching ALT keypress

Posted on 1999-10-22
11
Medium Priority
?
225 Views
Last Modified: 2010-04-16
Hi All,

I need to catch ALT pressed using interrupts (16H ), no idea on how, any input appriciated, thanks.
0
Comment
Question by:Bigozs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 12

Expert Comment

by:Hypo
ID: 2151094
Hi, I have written a keyboard handler for interrupt 9... It can read multiple keypresses at the same time, it can read any key that the keyboard has as well... It's written to replace/intercept with interrupt 9 though, If you want it... pass me your E-mail.
0
 

Author Comment

by:Bigozs
ID: 2151179
unfortunately i need this for 16h :(
0
 

Expert Comment

by:idok
ID: 2151219
Const KBD_INT = $16;
      ALT_MASK = $08;

Function IsAltPressed : Boolean;
Var
    Status : Byte;

Begin
 asm
   mov ah, $2
   int KBD_INT
   mov Status, al
 end;
 
 If ((Status and ALT_MASK) > 0) Then
   IsAltPressed := True
 Else
   IsAltPressed := False;

End;
 
----------------

Happy programming,
Ido.
0
New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

 
LVL 2

Expert Comment

by:kamarey
ID: 2151576
You can do it without any interrupt (so faster). The state of Alt key ( and some other keys ) placed in this address :
 0040:0017 in the BIOS Data Area.
bit  mask
 0:   01H   right-shift
 1:   02H   left-shift
 2:   04H   Ctrl
 3:   08H   Alt
 4:   10H   ScrollLock
 5:   20H   NumLock
 6:   40H   CapsLock

var
  i:byte;
begin
  i:=mem[$0040:$0017];
  if (i and 8)=0 then
     write('Alt key is pressed');
end.

Actually interrupt 16 function 2 uses
this address. There is another address
which can test difference between right
and left Alts.
0
 

Author Comment

by:Bigozs
ID: 2151736
Idok- this would work, but the thing is i need no ASM in it.

Kamarey- it has to be interrupts, not my idea, just been asked to do it that way =)


Thanks for the effort though, i know i didn't specify no Assembly :) sorry
0
 
LVL 12

Accepted Solution

by:
Hypo earned 240 total points
ID: 2151759
Hi,
Since you're not allowed to use assembler but you have to use interrupts, I replaced the asm part of Idoks answer with pascal code...

You have to use the DOS unit. (uses dos, etc...)

Const KBD_INT = $16;
      ALT_MASK = $08;

Function IsAltPressed : Boolean;
Var regs   : Registers;
    Status : Byte;

Begin
 regs.AH := $2;
 intr($16,regs);
 Status := regs.AL;
 If ((Status and ALT_MASK) > 0) Then
   IsAltPressed := True
 Else
   IsAltPressed := False;
End;
0
 

Expert Comment

by:idok
ID: 2151864
Oh well.
0
 
LVL 12

Expert Comment

by:Hypo
ID: 2152090
did I propose an answer to this question...? I thought I only posted a comment. I'm Sorry for that Idok.
0
 

Author Comment

by:Bigozs
ID: 2152217
oops, something went wrong?

sorry :(
0
 

Author Comment

by:Bigozs
ID: 2152345
oops, something went wrong?

sorry :(
0
 

Expert Comment

by:idok
ID: 2156886
Sure, hypo, no hard feelings.
Some you win, some you lose. ;-)

Bigozs: Ofcouse not - you got an answer to your problem, that's what this place is all about.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Shawn
IT teams define success as solving problems quickly. To enable ITSM modernization we have to think of adopting the tools and methods that will enable resolution of ITSM issues more quickly.
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question