Solved

keyboard hit..

Posted on 1998-05-26
11
417 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 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Grammars for C C++ and java 1 131
How to convert MFC::CString to UTF8 wchar_t* 10 293
C++ mouse_event mouse look 7 99
boost::uuid crashes 17 13
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

821 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