Sign in to follow this  
ade-the-heat

direct input for key presses

Recommended Posts

it's working fine most of the time - if I keep a key down then of course I can poll and find out it's down and say move the player. However, I'm having a real anoying problem: In my game the player has a machine gun. When the 'M' key is down the machine gun should fire all the while the M key is down. What is actually happening is that it fires once and won't fire again until I release the key and press it down again. Which is really annoying - and not realistic. Any ideas ? I only have this problem with the fire bullets and not speed up/speed down/move up/down etc //this is how I check the key down if (inputSystem->KeyDown(DIK_M)) OnKeyDown(VK_NUMPAD1); //this is what I do with it case VK_NUMPAD1: //fire bullets gameWorld->player->FireBullet(); //thisis the fire bullet func CurrentTime = GetTickCount(); if ((CurrentTime - bulletTime) > (float)TIME_BETWEEN_BULLETS) { sound->FireMachineGun(); //do collisions }

Share this post


Link to post
Share on other sites
Ok, here's my keyboard class:

class CKeyboard
{
CKeyboard(LPDIRECTINPUT8 pDI, HWND hwnd);
bool KeyDown(char key)
{return (m_keys[key] & 0x80) ? true : false;}
...etc
}

here's my input class:

class CInputSystem
{
bool KeyDown(char key) { return (m_pKeyboard && m_pKeyboard->KeyDown(key)); }

//etc...for mouse
}


Check Input Function:
=======================

//strafe right
//BELOW ALWAYS WORKS FINE
if (inputSystem->KeyDown(DIK_D))
OnKeyDown(VK_RIGHT);

//fire bullets
ONLY WORKS ONCE - THEN I HAVE TO RELEASE THE KEY AND REPRESS
if (inputSystem->KeyDown(DIK_M))
OnKeyDown(VK_NUMPAD1);

Hope this is helpful

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
onKeyDown?

well that event will only be called once - when you press the key and will not be called while you hold the key.

is there a OnKeyHeld event?
if so use that

if not, have a boolean "bKeyHeld" and OnKeyDown bKeyHeld = true and OnKeyUp bkeyHeld = false. Then you can use a loop to call fireBullet.

thats what i do usually for somethings.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this