Computer Engineers

 
Home | Computer engineering other top | Fiber / Wireless / Copper Tran | Semiconductor engineering
  Position:HOME>Programming language engineeri>Article Content
getch() function
Source:Internet Author:Unknow Pubdate:2008-04-14  
qUarC (Computer) 14 Jan 05 19:09
  I have written a simple game with a ball which bounces off the margins of the screen and at the bottom of the screen is my pad which is controlled by 'a' and 'd' buttons on my keyboard.:(simplified)
int c = 1;
while(1)
{
if(kbhit())
 {
  c = getch();
  if(c == 27) exit(1);
  if(c == 'a' || c == 'A') movepadleft();
  if(c == 'd' || c == 'D') movepadright();
 }
 movetheball();
}
 The thing that i don't like is: when i press a or d the pad moves for a short period of time, then stops and then moves constantly as long as i keep the button pressed.(it is the same thing just if i open notepad and press a letter: the letter i press apears, then there is a pause and then it prints that letter al long as i keep the button pressed).
  This function(getch()) is not suitable for this problem? What alternatives i have to solve the problem? 字串6
   

IRstuff (Aerospace) 14 Jan 05 19:27
I don't understand.  What do you want it to do instead? TTFN

qUarC (Computer) 14 Jan 05 19:34
  I want the pad to move constantly as long as i keep the buton pressed. That's all.

macgyvers2000 (Electrical) 14 Jan 05 22:30
You're bumping up against the keyboard repeat rate.  You'll need accessto the raw data from the keyboard specifying when a key-up/key-down action has occured.


IRstuff (Aerospace) 14 Jan 05 23:04
So you need to find the KeyPressed and KeyReleased or equivalent functions. TTFN

flamby (Structural) 15 Jan 05 3:53
字串5

Or you can perhaps change the typemetric(?) rate of your keyboard from BIOS settings. Ciao.

qUarC (Computer) 16 Jan 05 15:19
  And do you know what are the equivalent KeyPressed and KeyReleased functions because i have bc5.0 and i don't have them?

tendim (Computer) 9 Mar 05 16:50
What OS are you writing this in?  To get beyond the limitations of getch(), scanf(), etc., you may need to use an additional library.  On *nix systems ncurses comes to mind.

-10d

xwb (Computer) 2 May 05 12:24
Preseumably you are using Windows (kbhit doesn't exist on any other OS).  You can change the typemetric rate from keyboard properties.  The default is about .75 way down the scale.  If you change it to .25 way down, it might achieve what you want.
字串7




(Click:

Previous:Windows XP pagefile problem   Next:Programming a RJ45 Serial Port in Windows XP
[Add TO Favorites] [TOP] [PRINT] [CLOCE WINDOWS]  
  Hot Article
·PIC code for triac light dimme
·Connecting a Footswitch to an
·Siemens s7-200 PLC & Visua
·TETRIS source code is availabl
·XML Files and Terramodel
·controlling GPIB from VBA
·LINKING MSC PATRAN WITH INTRAN
·How to interface RS-485 / Modb
·VBA WITH AB PLC
·SIEMENS: I/O, NCDDE AND DCTL
·Visual Basic Serial Comms To S
·Symax PLC
  Related Articles
·Programming a RJ45 Serial Port
·airbag system
·Matlab ADD In
·what language should I use?
·fortran g77 interface with exc
·Matlab Demos on mozilla
·Interface webcam to DSP
·Embedded PIC C programming
·detecting a USB device
·writing code for delay rountin
·compile error?
·Basic GPIB setup
Power by DedeCms