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

Keyboard buffer

How can I feed an ascii code in the keyboard buffer
using Turbo-C (MS-DOS) platform ?
The software should interpret as if the keyboard has
been pressed
1 Solution
Use function int peek(address,offset) to get values from memory.

40:001a,2-bytes. Addr of keyboard buffer head (keystroke at that addr is next).
40:001c,2-bytes. Address of keyboard buffer tail.
40:001e,32-bytes. Keyboard buffer.  BIOS stores keystrokes here (head and tail point to addresses from 041eH to 043dH inclusive).

But i didn't tested if it work.
This solution is in assembly language.  It is assumed that as you are asking question in C you are familiar with assembly.

mov ah,3fh; {function 3fh of dos interrupt}
mov bx,0;{handle for standard input}
mov cx,80h;{Maximum bytes to read}
mov dx,seg buffer;{DS:DX Buffer address}
mov ds,dx;
mov dx,offset buffer;
int 21h;

what essentially u're doin' in this is that opening the console as a file.  Embed this code in C as some function.
Don't forget to add _asm before you write the declarations.
pan_kajAuthor Commented:
The answer proposed by kamarey is very cryptic and I am
unable to understand it.

I will appreciate a function which accepts an ASCII char as an
input and puts it in keyboard buffer something like given below:

void put_kb_buffer(char a)


Will somebody help ?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Prepare for an Exciting Career in Cybersecurity

Help prevent cyber-threats and provide solutions to safeguard our global digital economy. Earn your MS in Cybersecurity. WGU’s MSCSIA degree program curriculum features two internationally recognized certifications from the EC-Council at no additional time or cost.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now