Stoping keybord beeps.

Posted on 2000-04-30
Last Modified: 2010-05-19
Ok, easy question for most, but I sure can't find anything on it.  When you hold down any repeating key, the keybord will beep. (I think that's 'cause the buffer is full) How do you stop this? As it stands now, I can't use and arrow keys in games, unless the player just keeps hitting them.  They can't hold them down, or the buffer fills up.

P.S. Why isn't this explained in the help files, or in an on-line file?
Question by:Ozzy_98
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 48

Expert Comment

ID: 2765247
You are talking programming aren't you?  Aren't you testing to see if keystroke available and grabbing when there?


  while keypressed
       ch := readkey     { standard keys }
       if ch = #0 then
         ch := readkey;  { extended key like arrow keys }

Expert Comment

ID: 2765540
I have some code for that question. Give me some hours and I will post it.

Bye, TDS.

Accepted Solution

Mathias earned 20 total points
ID: 2765606
This is the code for clearing the keyboard buffer.
Please note that this don't work under windows!

Bye and good luck for your games, TDS.

{ - - - - - - - - - }

const KBD_NO_DATA  : Integer = -1;      {* No data *}
      KBD_BAD_DATA : Integer = -2;      {* Parity or other error *}

      KBD_STATUS_REG = $64;    { Status register (R)  }
      KBD_DATA_REG = $60;      { Keyboard data register (R/W)  }
      KBD_STAT_OBF = $01;      { Keyboard output buffer full  }
      KBD_STAT_GTO = $40;      { General receive/xmit timeout  }
      KBD_STAT_PERR = $80;     { Parity error  }

function kbd_read_input: Integer;
var retval: Integer;
    status, data: Byte;
  retval := KBD_NO_DATA;
  status := Port[KBD_STATUS_REG];
  if (status and KBD_STAT_OBF <> 0) then
    data := Port[KBD_DATA_REG];
    retval := data;
    if (status and (KBD_STAT_GTO or KBD_STAT_PERR) <> 0) then
      retval := KBD_BAD_DATA;

procedure kbd_clear_input;
var maxread: Byte;
  while maxread > 0 do
    if (kbd_read_input = KBD_NO_DATA) then

  kbd_clear_input; {clear the keyboard buffer}
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

LVL 12

Expert Comment

ID: 2767465
You have to get the keystrokes in a correct way. See DBrutons comment.

Some keys are extended (the arrows for instance) and sends a 0 before the actual scancode. If you don't read the scancode that comes after the "Extended key byte" (the zero), the actual scancode will stay in the buffer.

See this example, you won't get any beep's here???

(Move the cursor around with your arrowkeys, try holding them down aswell)
Program test;
uses crt;

var Key : byte;
    Ext : boolean;

    Xpos,Ypos : shortint;

Procedure GetKey;
 Key := ord(readkey);
 If Key = 0 then begin
  Ext := true;
  Key := ord(readkey);
 end else Ext := false;

 Xpos := 1;
 YPos := 1;
  if Ext then begin
   if Key = 72 then Ypos := (Ypos - 1);
   if Key = 80 then Ypos := (Ypos + 1);
   if Key = 75 then Xpos := (Xpos - 1);
   if Key = 77 then Xpos := (Xpos + 1);
   If (YPos < 1)  then YPos := 25;
   If (YPos > 25) then YPos := 1;
   If (XPos < 1)  then XPos := 80;
   If (XPos > 80) then XPos := 1;
 until key=27;

Author Comment

ID: 2767820
Damn, I feel stupid. :(

Sorry guys, I didn't erase this question in time, and I hope you didn't spend too much time writing your answers.  My problem was just a stupid mistake, and I paid for it.  I already know about extended keys, since someone else asked that. (See? People do look at the other questions before asking new ones.) As a matter of fact, my readkey looks almost word-for-word like Hypo's, so I bet he was the one who answered that question, which tought me how to use it.  I didn't relize that it only beeped at me on my old programs I wrote in high school, so I didn't need to ask it.  
Im giving TDS the points, since I like the code he sent, and can always use new stuff.  But I'm thanking you two, Hypo and dbrunton, for the posts.  Like I said, didn't realise I knew the answer before I asked the question.

P.S.  If Hypo was the one that I learned extended keys off of, then he was the first to answer this question. :)

P.P.S. I have the scan codes for F1-F10, but I can't get F11 and F12 to read right.  What's special about them? Did they add those two later or something? Just asking.
LVL 48

Expert Comment

ID: 2768317

The original PC had function keys F1 to F10.
When the AT was introduced the keys went F1 to F12.

The software DOS changed to reflect that.   DOS uses INT 16H functions 00h and 01h to test and read characters from the keyboard on PC keyboards.  On AT keyboards DOS uses INT 16H functions 16h and 17h to test and read the keyboard.

On startup DOS checks the BIOS to see which keyboard is present and uses the appropriate functions.  Turbo still uses the 00h and 01h functions to read the keyboard and hence doesn't understand F11 and F12.

There are replacement CRT units out there that will read the F11 and F12 keys.

Expert Comment

ID: 2768584
It is easier, my opinion, to control the keyboard in a direct way (Port $60-$64). This solution can also handle keys like the windows keys. If anybody is interested in, I can post a unit with the keyboard handler and the key description.

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
default value in Delphi component 2 526
I would like to parse a DBF file via Delphi XE5 can anyone help me? 7 360
Activex get website that activex running on 3 108
code issue 8 215
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Suggested Courses

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question