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

[.net] [C#]SDL.net, Keyboard Help

Started by lucas92 Jul 9, 2009 at 6:35 PM 1 replies 1.7k views
Original Post
lucas92
lucas92
What's the best way to check the Keyboard inputs from the user? I've tried many things but I end up being stuck when I press 3 keys...
rip-off
rip-off
Your keyboard is probably at fault. If you research how they work, you will discover that certain combinations of keys cannot be pressed simultaneously. Picking different keys might work.
lucas92
lucas92
That's interesting. Well, I guess this isn't my fault.

Here's the way I manage the input, just to know if there's a better way to do it...

        void Events_KeyboardUp(object sender, KeyboardEventArgs e)        {            if (e.Key == Key.A)            {                left = false;            }            if (e.Key == Key.D)            {                right = false;            }            if (e.Key == Key.W)            {                up = false;            }            if (e.Key == Key.S)            {                down = false;            }        }        void Events_KeyboardDown(object sender, KeyboardEventArgs e)        {            if (e.Key == Key.A)            {                left = true;            }            if (e.Key == Key.D)            {                right = true;            }            if (e.Key == Key.W)            {                up = true;            }            if (e.Key == Key.S)            {                down = true;            }            UpdatePosition();         }        void UpdatePosition()        {            if (left)            {                circle.PositionX--;            }            if (right)            {                circle.PositionX++;            }            if (up)            {                circle.PositionY--;            }            if (down)            {                circle.PositionY++;            }        }


It moves a circle around the screen.

Topic Locked

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

Sign in to reply to this topic.