×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to check if a key was pressed?

How to check if a key was pressed?

How to check if a key was pressed?

(OP)
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.
Replies continue below

Recommended for you

RE: How to check if a key was pressed?

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

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

Marcel

RE: How to check if a key was pressed?

(OP)
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.

RE: How to check if a key was pressed?

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

RE: How to check if a key was pressed?

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close