• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

Catching ALT keypress

Hi All,

I need to catch ALT pressed using interrupts (16H ), no idea on how, any input appriciated, thanks.
0
Bigozs
Asked:
Bigozs
  • 4
  • 3
  • 3
  • +1
1 Solution
 
HypoCommented:
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
 
BigozsAuthor Commented:
unfortunately i need this for 16h :(
0
 
idokCommented:
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
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.

 
kamareyCommented:
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
 
BigozsAuthor Commented:
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
 
HypoCommented:
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
 
idokCommented:
Oh well.
0
 
HypoCommented:
did I propose an answer to this question...? I thought I only posted a comment. I'm Sorry for that Idok.
0
 
BigozsAuthor Commented:
oops, something went wrong?

sorry :(
0
 
BigozsAuthor Commented:
oops, something went wrong?

sorry :(
0
 
idokCommented:
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

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now