Solved

keyboard hit..

Posted on 1998-05-26
11
418 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
[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
  • 5
  • 5
11 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 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
Independent Software Vendors: 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 84

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ standard library based binary archive format 6 112
typedef std::deque<BYTE> ByteVector is broken in vs2012 23 94
White board coding practice 3 98
Outlook 13 100
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

738 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