Sign in to follow this  

Getting multiple key presses under DOS

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been trying to find out in DOS if a user presses more than 1 key.I tired using kbhit() and getch() and an array to store presses but that did not work ;). Any idea/suggestions on what to do? Also how to recognise keys like Funtion keys and the Alt,Ctrl key?

Share this post


Link to post
Share on other sites
Hi,

I remember some port (it was 0x60, but not sure) from which you could read the press and release of keys. If you maintain a table from this info, you can handle multiple key presses. The number of simultaneous key presses you an handle this way seemed to depend on the keyboar as far as I remember, but i managed 5 or so...
Oh, tha keys have some different codes, not ascii, and when you release a button, then you get the code that you get when pressing+128 (highest but set).

Hope you will succeed!

Peter

Share this post


Link to post
Share on other sites
If you can check out any of LaMothes early books He covers this in every dos game programming book he wrote. Also, I remember there being a library floating around the net, I believe it was called the Z Keyboard Handler but I didn't have any luck finding it with the quick google I just tried.

I've found a few details from Tricks of the Game Programming Gurus, Chapter 12.

The keyboard uses interupt 0x09, you need to install a new ISR routine for the keyboard at this interupt to handle multiple keypresses.

The ISR takes control when the interupt fires, then it reads from the ports to determine what changed on the keyboard.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you are making a game you might as well use Allegro library for DOS.

Share this post


Link to post
Share on other sites
Here's the old code i used in Turbo Pascal. It basically installs an Interrupt handler for the keyboard interrupt and sets flags in an array. Shouldn't be any problem converting to another language.

Maybe you have to change the accessing of the variable from the assembler, as this is 16-bit.

Asm-Include

data segment word public
extrn buttonpressed:near
data ends

code segment byte public
public int09@obj
assume cs:code, ds:data

int09 proc far

push ax
push bx
push dx
push ds

mov ax,data
mov ds,ax

in al,60h
xor ah,ah
mov bx,ax

test bx,80h
jz pressed

; released

xor bx,80h
mov buttonpressed[bx],0
jmp short theend

pressed:

mov buttonpressed[bx],1

theend:

mov dx,61h
in al,dx
or al,80h
out dx,al
xor a1,80h
out dx,al

mov al,20h
out 20h,al

pop ds
pop dx
pop bx
pop ax

iret

int09 endp


code ends




Pascal Unit:

unit manykeys;

interface

uses dos;

const initflag:boolean=false;

var buttonpressed:array [$00..$7f] of boolean;

procedure initmanykey;
procedure reinitmanykey;

implementation

var saveint09,saveexitproc:pointer;

procedure int09; external; {$L int09.obj}

procedure initmanykey;
begin
if not initflag then
begin
fillchar(buttonpressed,128,char(false));
getintvec($09,saveint09);
setintvec($09,@int09);
initflag:=true;
end;
end;

procedure reinitmanykey;
begin
if initflag then
begin
setintvec($09,saveint09);
initflag:=false;
end;
end;

{$F+}
procedure manykeyexit;
begin
reinitmanykey;
exitproc:=saveexitproc;
end;
{$F-}

begin
saveexitproc:=exitproc;
exitproc:=@manykeyexit;
end.

Share this post


Link to post
Share on other sites

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this