Solved

Stoping keybord beeps.

Posted on 2000-04-30
7
210 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
[X]
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
7 Comments
 
LVL 49

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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 49

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Justin
In light of the WannaCry ransomware attack that affected millions of Windows machines, you might wonder if your Mac needs protecting. Yes, it does and here is how to do it.
We take a look at some of the most common obstacles that IT teams run into as they work relentlessly to keep all the alarms and sirens from going off at once.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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