Click here to Skip to main content
15,881,881 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralAccelerator Pin
San21-Aug-01 1:20
San21-Aug-01 1:20 
GeneralRe: Accelerator Pin
Christian Graus21-Aug-01 2:08
protectorChristian Graus21-Aug-01 2:08 
GeneralRe: Accelerator Pin
KingsGambit21-Aug-01 2:10
KingsGambit21-Aug-01 2:10 
GeneralMS WebBrowser - Java applet TextArea problem ! :( Pin
im_srini21-Aug-01 0:12
im_srini21-Aug-01 0:12 
GeneralKeyboard and Game! Pin
21-Aug-01 0:09
suss21-Aug-01 0:09 
GeneralRe: Keyboard and Game! Pin
Christian Graus21-Aug-01 0:30
protectorChristian Graus21-Aug-01 0:30 
GeneralRe: Keyboard and Game! Pin
Ulf Öhlén21-Aug-01 0:50
Ulf Öhlén21-Aug-01 0:50 
GeneralRe: Keyboard and Game! Pin
Pavlos Touboulidis21-Aug-01 11:32
Pavlos Touboulidis21-Aug-01 11:32 
Most games have a "main loop", in conjuction with some timer code to make it run at a constant rate. You can also make a game behaving like a standard application - I mean make it event driven. Of course, you can combine these two...
Here is some pseudocode for the 1st and 2nd type:

Main Loop
do
{
   if (is_key_down(LEFT_ARROW_KEY))
       player.MoveLeft();
   if (is_key_down(RIGHT_ARROW_KEY))
       player.MoveRight();

   draw_background();
   draw_sprites();
   draw_info();

   timer_sync_code();

}while(!is_key_down(ESCAPE));


Event Driven Here, the main loop is the standard message dispatcher
MyApp::OnTimer()
{
   draw_background();
   draw_sprites();
   draw_info();
}

MyApp::OnKeyPressed(int key)
{
   switch(key)
   {
      case LEFT_ARROW_KEY:
         player.MoveLeft();
         break;
      case RIGHT_ARROW_KEY:
         player.MoveRight();
         break;
      etc, etc, etc
   }
}


The reason you have this problem is because windows sends WM_CHAR and WM_KEYDOWN messages using the keyboard delay and repeat rate. If it wasn't like that, it would be impossible to typeeeeeeeeeeeeee;)


  1. One way would be to use DirectInput (part of DirectX). I haven't used it, but I'm sure it won't be hard.
  2. If you're using the game loop method, you could replace the pseudo-is_key_down functions with GetKeyState() (or GetAsyncKeyState()). These functions take the virtual key you're interested in as parameter and return the status of that key. If I remember correctly, you should "and" the return value with 0x8000 to get the pressed/unpressed state.
  3. If you're using the OnTimer() and OnKey() method, you can remove the OnKey() function and use what I wrote above in (2), inside OnTimer().

Questionwhy the release version component run error ? Pin
Sandos Ganzales21-Aug-01 0:08
Sandos Ganzales21-Aug-01 0:08 
AnswerRe: why the release version component run error ? Pin
Christian Graus21-Aug-01 0:33
protectorChristian Graus21-Aug-01 0:33 
GeneralVC Addin technical question Pin
Andreas Saurwein20-Aug-01 23:57
Andreas Saurwein20-Aug-01 23:57 
GeneralRe: VC Addin technical question Pin
Christian Graus21-Aug-01 0:34
protectorChristian Graus21-Aug-01 0:34 
GeneralRe: VC Addin technical question Pin
Andreas Saurwein22-Aug-01 13:38
Andreas Saurwein22-Aug-01 13:38 
GeneralRe: VC Addin technical question Pin
Christian Graus22-Aug-01 13:46
protectorChristian Graus22-Aug-01 13:46 
GeneralRe: VC Addin technical question Pin
Anna-Jayne Metcalfe21-Aug-01 0:44
Anna-Jayne Metcalfe21-Aug-01 0:44 
GeneralRe: VC Addin technical question Pin
Andreas Saurwein21-Aug-01 1:03
Andreas Saurwein21-Aug-01 1:03 
GeneralCString to CLongBinary Pin
20-Aug-01 23:56
suss20-Aug-01 23:56 
GeneralRe: CString to CLongBinary Pin
Ryszard Krakowiak21-Aug-01 3:54
Ryszard Krakowiak21-Aug-01 3:54 
GeneralRe: CString to CLongBinary Pin
21-Aug-01 4:40
suss21-Aug-01 4:40 
GeneralRe: CString to CLongBinary Pin
Uwe Keim21-Aug-01 4:00
sitebuilderUwe Keim21-Aug-01 4:00 
GeneralRe: CString to CLongBinary Pin
Giles21-Aug-01 4:42
Giles21-Aug-01 4:42 
GeneralRe: CString to CLongBinary Pin
Uwe Keim21-Aug-01 4:51
sitebuilderUwe Keim21-Aug-01 4:51 
Generalwhats wrong here??about waveinreset!! Pin
hapcoer20-Aug-01 23:43
hapcoer20-Aug-01 23:43 
Generala simple question about global variable Pin
Gérald Mercet20-Aug-01 23:04
Gérald Mercet20-Aug-01 23:04 
GeneralRe: a simple question about global variable Pin
Christian Graus20-Aug-01 23:29
protectorChristian Graus20-Aug-01 23:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.