Original Post
I used many hours searching for a solution from the internet, reading my books and going trough dozens of DI related topics here, but finally gave up and decided to ask here. I have been doing all kinds of games, physic engines and AI systems for a long time, but I have never had the need to use DirectInput... the Win32 functions have been enough to suit my needs. I have been using DirectDraw for all my drawing, but now moved on to D3D, and at the same time started using DirectInput. My problem is that when I press a key, it reacts to it, then takes a 0.5 second brake and then continues reacting fluently, just like the auto repeat works when you type. Now, this happens each time I press a new key, and stops everything for a while, even reactions to other keys, but everything continues like before after the "auto repeat" delay has ended. There is no delay nor problem when a key is released. First I tought that I must be just doing something so badly that it tilts for a second when you do something new, but then I noticed another problem that changes my guess from the previouse one to "I do not know at all" or "must be something with the window being..... I do not know": When you release all keys, the movement stops totally. Let me first show you the code so you get it (yes, this is just a test, and nothing clean... I just wanted to see if I can get it working): Player is a structure that includes the location, x and y, the velocities, xv and yv, and the texture of the player, texture. Also, as you can see, I am using the macro DI SDK suggests for testing key input; #define KEYDOWN(name, key) (name[key] & 0x80) So yeah, if no keys are pressed, the player just stops moving, like the game would stop and wait for input before continuing. If you are going max speed to the left, and releaste the left arrow, the player stops like into a wall, and then if you for example press the right arrow down, the player continues left like the xv is telling it, before the velocity is slowly turned around. So, to me it seems that the game like pauses, to wait for input. This problem is in both full screen and windowed mode, and does not depend on any window styles. Now, to the thing that made me just stare at the screen and want to call my mother is that when you move the mouse on the game window, everything works. Everything works smoothly when the mouse is constantly MOVING on the game window, thus sending input messages to the window, even tough I do not know why that would affect this, as at least I have not set anything that I could think of archieving this. Also, when you are moving max speed to a direction, and then stop pressing keys, the game stops, like I said. Now, if you move the cursor across the screen, the player starts moving again just like the velocity tells it to do. I am not sure, but I think this same problem occured when I used the Win32 functions for this.... now that I think of it.... I think that was actually why I wanted to try DI for this, so the problem might be something totally else. Here is the initialization code if it helps: Thank you very much in advance! I really appreciate your help. Pauli
diDevice->GetDeviceState( sizeof(diKeyboard), (LPVOID)diKeyboard );
if ( KEYDOWN( diKeyboard, DIK_LEFT ) && player1.xv > -10.0f )
player1.xv -= 0.5f;
if ( KEYDOWN( diKeyboard, DIK_RIGHT ) && player1.xv < 10.0f )
player1.xv += 0.5f;
if ( !KEYDOWN( diKeyboard, DIK_LEFT ) && player1.xv < 0 )
player1.xv += 0.5f;
if ( !KEYDOWN( diKeyboard, DIK_RIGHT ) && player1.xv > 0 )
player1.xv -= 0.5f;
if ( KEYDOWN( diKeyboard, DIK_UP ) && player1.yv > -10.0f )
player1.yv -= 0.5f;
if ( KEYDOWN( diKeyboard, DIK_DOWN ) && player1.yv < 10.0f )
player1.yv += 0.5f;
if ( !KEYDOWN( diKeyboard, DIK_UP ) && player1.yv < 0 )
player1.yv += 0.5f;
if ( !KEYDOWN( diKeyboard, DIK_DOWN ) && player1.yv > 0 )
player1.yv -= 0.5f;
player1.x += player1.xv;
player1.y += player1.yv;
if ( FAILED( DirectInput8Create( application_hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&di, NULL ) ) )
return E_FAIL;
if ( FAILED( di->CreateDevice( GUID_SysKeyboard, &diDevice, NULL ) ) )
return E_FAIL;
if ( FAILED( diDevice->SetDataFormat( &c_dfDIKeyboard ) ) )
return E_FAIL;
if ( FAILED( diDevice->SetCooperativeLevel( main_window_handle, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE ) ) )
return E_FAIL;
if ( FAILED( diDevice->Acquire() ) )
return E_FAIL;