Adam's Lair Forum

game development and casual madness
It is currently 2018/01/23, 11:48

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: 2017/09/03, 19:33 
Newbie
Newbie

Joined: 2017/08/13, 16:30
Posts: 5
Role: Hobbyist
I have got a weird problem in my game. I can fly a ship around on the screen with the arrow keys, and shoot with the Space key. The ship can fly in all directions, including diagonals, by holding two arrow keys at the same time. Now the problem:

Hold Space + Right key + Up key => Works, ship shoots and flies up and to the right
Hold Space + Right key + Down key => Works, ship shoots and flies down and to the right
Hold Space + Left key + Down key => Works, ship shoots and flies down and to the lleft
Hold Space + Left key + Up key => DOES NOT WORK! Ship either just fly up and left without shooting, or shoots and stays still, depending on whatever keys I press first.

I have logged the keys being pressed with Log.Game.Write(....) and inspecting the log it clearly can be seen that the combinaition of Space key, Left arrow key, Up arrow key is never logged.

Code:
[Game] Msg: Pressed: Space UpKey RightKey
[Game] Msg: Pressed: Space RightKey DownKey
[Game] Msg: Pressed: Space DownKey LeftKey
[Game] Msg: Pressed: UpKey LeftKey


Here is my code

Code:
public void OnUpdate()
        {
            ClearInputLog();

            CheckKeysPressedDown();

            WriteInputLog();
        }

private void ClearInputLog()
        {
            keysPressedString = "";
            keysReleasedString = "";
        }

        private void WriteInputLog()
        {
            if (keysPressedString != "" || keysReleasedString != "")
            {
                string s = string.Format("Pressed: {0}     Released: {1}", keysPressedString, keysReleasedString);
                Log.Game.Write(s);
            }
        }

private void CheckKeysPressedDown()
        {
            // Space key - Player shoot
            if (DualityApp.Keyboard.KeyPressed(Key.Space))
            {
                keysPressedString += "Space ";
                PlayerShip.FireKeyPressed();
            }

            // ********************* Start movement ******************
            int dx = 0;
            int dy = 0;
            if (DualityApp.Keyboard.KeyPressed(Key.Up))
            {
                keysPressedString += "UpKey ";
                dy = -1;
            }
            if (DualityApp.Keyboard.KeyPressed(Key.Right))
            {
                keysPressedString += "RightKey ";
                dx = 1;
            }                   
            if (DualityApp.Keyboard.KeyPressed(Key.Down))
            {
                keysPressedString += "DownKey ";
                dy = 1;
            }
            if (DualityApp.Keyboard.KeyPressed(Key.Left))
            {
                keysPressedString += "LeftKey ";
                dx = -1;
            }
            if (dx != 0 || dy != 0)
                PlayerShip.MovementKeyPressed(dx, dy);
            // ********************* End movement ******************

        }


Anyone know what's going on??


Top
 Profile  
 
PostPosted: 2017/09/03, 19:56 
Forum Addict
Forum Addict
User avatar

Joined: 2013/09/19, 14:31
Posts: 856
Location: Italy
Role: Hobbyist
Unfortunately it's 99.99% a side-effect of your keyboard's hardware, due to the way they are built. Basically, the circuits that are build under the keys don't allow more than one key in the same "region" to be pressed at the same time. Most keyboard operate in what's known as 2-key rollover (you'll find 2KRO on google) on most of the keys, while the ones usually more associated with games (arrows, WASD) could be built on 3 or 4KRO circuits. Shift, Alt, and Ctrl tend to be separate as well, that's why you can usually keep them pressed as well.
This is especially true for laptops, where space is even more critical than a normal keyboard.

Potentially, the maximum you can have on a USB keyboard is a 6KRO (i.e. 6 keys pressed at the same time), while the old PS2 connections have no set limit (NKRO).

From what you said, you almost certainly have Space, Up and Left on the same region, in a 2KRO configuration.. which means you can have at most 2 keys in the same region pressed at the same time.

tl;dr; nothing you can do, besides buying another (possibly gaming) keyboard.

_________________
Come on Duality's Discord channel. It's entertaining and productive! :mrgreen:


Top
 Profile  
 
PostPosted: 2017/09/04, 10:06 
Newbie
Newbie

Joined: 2017/08/13, 16:30
Posts: 5
Role: Hobbyist
Interesting. You learn something new every day. Thanks for the great explanation! This must be it, I have an old USB keyboard.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group