Skip to main content
GameDev.net gamedev.net
🔒 Locked

direct input for key presses

Started by ade-the-heat Nov 24, 2004 at 5:57 PM 4 replies 1.1k views
Original Post
ade-the-heat
ade-the-heat
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 }
IFooBar
IFooBar
Can we see your KeyDown function and where you poll the input devices?
[size=2]aliak.net
ade-the-heat
ade-the-heat
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
Alex Swinney
Alex Swinney
What does FireBullet() look like?
I WISH SOMEONE WOULD FIX THE DAMNED LOGIN!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.