Jump to content
  • Advertisement
Sign in to follow this  

Getting multiple key presses under DOS

This topic is 5171 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

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!


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.


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


mov buttonpressed[bx],1


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


int09 endp

code ends

Pascal Unit:

unit manykeys;


uses dos;

const initflag:boolean=false;

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

procedure initmanykey;
procedure reinitmanykey;


var saveint09,saveexitproc:pointer;

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

procedure initmanykey;
if not initflag then

procedure reinitmanykey;
if initflag then

procedure manykeyexit;


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!