Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

keyboard hit..

Posted on 1998-05-26
11
Medium Priority
?
423 Views
Last Modified: 2008-03-17
Hi!
I wanted to know if there is a way to cancel the delay in the keystrokes? for example:
if (kbhit()) c=getch();
say the user, presses left, so x-=10.
and if the user continues to press the left key, then continue wiith x-=10.
but there is a delay, right after the user presses, and until it starts to do c-=10 for the second time.
i know that i can minimize the delay with the command (in dos prompt):
mode con rate=32 delay=1

but there is still a delay!!!
how do i cancel it totally?!
  thanks, Yoli.

0
Comment
Question by:yolis
  • 5
  • 5
11 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 1164746
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164747
No, you can't cancel the delay between the initial keystroke and and the first repeated key.  This delay is produced a chip in the keyboard itself.  However, you can program the chip to reduce the delay to 250 ms, which is 1/4 of a second, from a DOS program.

continues
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164748
The following assembly code will set keyboard rate to its highest value and the delay to its lowest value.

__asm
{
   MOV AX,0305H
   MOV BX,0
   INT 16H
}
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 85

Expert Comment

by:ozo
ID: 1164749
You could also emulate any rate you want by tracking the key-down and key-up events separately.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164750
I beleive this is for a DOS program, so there are no key-down and key-up events.  However you could hook the keyboard interrupt and do the same thing.  However, My experience has been that this is not a great idea.  Better to rethink your design and examine all options before going in that direction.
0
 

Author Comment

by:yolis
ID: 1164751
Thanx ALOT!

0
 

Author Comment

by:yolis
ID: 1164752
Thanx ALOT!

0
 

Author Comment

by:yolis
ID: 1164753
Hmm... the assembly code, is not good enough, there is still a delay..

so, I tried to do track the key up and key down events saparetly using this code:

int movment=0;
while (ch!=27) {
movment=kbhit();
if (movment==1) {
do the stuff i want when there is a kbhit()...
}
if (!kbhit()) movment==0;
}

why isnt this working?
please help..

0
 

Author Comment

by:yolis
ID: 1164754
a correction for the code in the comment i wrote before, here is the function:
int game()
{
  int i2;
  char ch;
  int movment=0;
  int bla=0;
  while (ch!=27)
  {
    move_enemies();
    if(alive>=1) for(i2=0;i2<10*speed;i2++)
    {
      delay(1);
      if(yfire!=1 && i2%10==0) fire();
      if(i2%20==0) fire_enemies();
      if (movment==0)
      { movment=kbhit(); bla=0; }
      if (movment!=0)
      {
      if (bla==0) { ch=getch();
      bla=1;  }
      switch(ch)
      {
        case 75: x-=10; draw_me(); break;
        case 77: x+=10; draw_me(); break;
        case 32: clearfire(); yfire=2; xfire=x; break;
        case 27: X=2;
      }
      }
      if (!kbhit())  movment=0;


      if(X!=0) return(X);
    }
    if(alive==0) return (3);
  }
  return 0;
}

0
 
LVL 22

Expert Comment

by:nietod
ID: 1164755
_kbhit just checks the DOS key queue to see if there is a waiting key.  Your problem is the delay in keys being placed in there.

Your best solution is to handle the keyboard interrupt dirrectly, or at least to hook it.  It is called when any key pressed or released, so you can use it to keep track of what keys are down.

I reccomend you get a hold of "PC interrupts" by Ralph Brown if you don't have it already.  You will need to know how to handle int 9 and how to communicate with the keyboard to find out what key is down.
0
 

Author Comment

by:yolis
ID: 1164756
thanks, I will try to search for it..

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

916 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