Solved

Stoping keybord beeps.

Posted on 2000-04-30
7
205 Views
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?
0
Comment
Question by:Ozzy_98
7 Comments
 
LVL 47

Expert Comment

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

Roughly

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

Expert Comment

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

Bye, TDS.
0
 
LVL 3

Accepted Solution

by:
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;
begin
  retval := KBD_NO_DATA;
  status := Port[KBD_STATUS_REG];
  if (status and KBD_STAT_OBF <> 0) then
  begin
    data := Port[KBD_DATA_REG];
    retval := data;
    if (status and (KBD_STAT_GTO or KBD_STAT_PERR) <> 0) then
      retval := KBD_BAD_DATA;
  end;
  kbd_read_input:=retval;
end;

procedure kbd_clear_input;
var maxread: Byte;
begin
  maxread:=100;
  while maxread > 0 do
  begin
    if (kbd_read_input = KBD_NO_DATA) then
      break;
    dec(maxread);
  end;
end;

begin
  kbd_clear_input; {clear the keyboard buffer}
end.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 12

Expert Comment

by:Hypo
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;
begin
 Key := ord(readkey);
 If Key = 0 then begin
  Ext := true;
  Key := ord(readkey);
 end else Ext := false;
end;



begin
 clrscr;
 Xpos := 1;
 YPos := 1;
 repeat
  GetKey;
  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;
  end;
  GotoXy(Xpos,Ypos);
 until key=27;
 clrscr;
end.
0
 

Author Comment

by:Ozzy_98
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.
0
 
LVL 47

Expert Comment

by:dbrunton
ID: 2768317
OK

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.
0
 
LVL 3

Expert Comment

by:Mathias
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.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now