Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check if a key was pressed? 1

Status
Not open for further replies.

Theherod

Programmer
Jun 28, 2007
6
Hello,

I use assembly 16b for dos (tasm), and I'm looking for a way to check if a key was pressed. Something like ah=7/int 21h, but, instead of waiting for a key to be pressed, it will check if a key was pressed (and if it happened indeed, to get its ascii code).

I build a simulation, and I want to know if the the user has pressed some key, while the simulation ran. But I don't want it to stop the simulation each frame... (which is why I don't use ah=7/int 21h).

Any suggestion anyone? I think there's an interrupt for that, but I'm not sure...

Thanks a lot!:)

Best regards,
Gal.
 
ah=0bh / int 21h --> check if a keyboard character is available.

out al --> 0 = no character available, ffh = character available



Marcel
 
Great, thanks a lot!

One more question, if I may ask...
I tried to use int 10h/ah 13h to print a string in mode 13. I've been told that in bl, the low 4 bits set the background color, and the high 4 bits set the foreground color, but, whatever I do, it does not change the background color. Is it possible to print a string with a background color different of black (in mode 13)?
(I didn't found also another interrupt with an option to choose a background color.)

Again, thanks a lot!

Gal.
 
Sorry Gal, i don't know about int 10h which is a BIOS interrupt and not a DOS one.

Using DOS interrupts it would be:

1. Be sure ANSI.SYS driver is loaded.

2. Get a handle to the display device.
- Let ds:dx point to a null-terminated string containing "CON"
- cx <-- 0
- ax <-- 3c00h
- int 21h
- if carry set, error
- otherwise ax contains handle

3. print the string using ANSI.SYS escape sequences to set color
- bx <-- handle
- cx <-- length of string
- ds:dx points to string to be written
- ax <-- 4000h
- int 21h
- if carry set, error
- otherwise ax contains number of bytes written
Repeat this step as much as required.

ANSI.SYS escape sequence for setting color is ESC (1bh) + "[" + <colorstring> + "m"
<colorstring> = a foregroundcolor, or a backgroundcolor, or a foregroundcolor and a backgroundcolor separated by a ";"
Foregroundcolors are "30" .. "37" for black, red, green, yellow, blue, violet, cyan and white
Backgroundcolors are "40" .. "47" for the same colors.

4. Close the handle to the display device
- bx <-- handle
- ax <-- 3e00h
- int 21h
- if carry set, error



Marcel
 
I dont know, what mode 13 is. Did you mean 0Dh? It is a
graphic mode, so background attributes will not work.

Try int 10h, ah = 09h:
bh - video page number,
al - character to write,
cx - repeat count,
bl - video attribute.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top