Jump to content
  • Advertisement
Sign in to follow this  
giugio

keyboard input

This topic is 3768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hy. I'm a beginner game programmer and i would create a wolfestain 3d of ID demo. I use opengl for create the world and gluLookAt for move in the world But how to create the keyboard control of the game? In particular how move in world both in the left and in the top ? This is the simlified code: case WM_RBUTTONUP: // right button release break; case WM_KEYUP: break; case WM_KEYDOWN: int fwKeys; LPARAM keyData; fwKeys = (int)wParam; // virtual-key code keyData = lParam; // key data switch(fwKeys) { case VK_ESCAPE: PostQuitMessage(0); break; case VK_ADD: m_dCenterZ += 0.1; break; case VK_SUBTRACT: m_dCenterZ -= 0.1; break; case VK_UP: m_dViewZ -= 0.1; break; case VK_DOWN: m_dViewZ += 0.1; break; ecc... where the m_dViewZ is the z coordinates of the camera in the gluLookAt function. There are some library for interact with the keyboard and in the future with the joipad? Thaks. [Edited by - giugio on June 28, 2008 1:51:36 PM]

Share this post


Link to post
Share on other sites
Advertisement
I do it like this



const int NO_KEYS = // however many keys

enum KeyboardKeys
{
KEY_LEFT = 0,
KEY_RIGHT,
// etc
};

class Keyboard
{
bool m_keys[ NO_KEYS ];

public:
bool IsPressed( KeyboardKeys key )
{ return m_keys[ key ]; }

void Update()
{
if ( GetAsyncKeyState( VK_LEFT ) )
m_keys[ KEY_LEFT ] = true;
if ( GetAsyncKeyState( VK_RIGHT ) )
m_keys[ KEY_RIGHT ] = true;
// and so on
}
};



Share this post


Link to post
Share on other sites
thanks a lot Mathmo.
I test the code and is that i need.
But a note:i read something about a library for the inputs device such mouse or keyboard or joypad.
Is a good choise for start?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!