简体   繁体   中英

C#/Monogame: shift keys blocked by arrow keys?

I often found useful informations here, now it was time to create an account on my own and say thanks to this community for it helped me so often!

I am currently coding a game in Monogame 3.2 in Mac OSX 10.9.5 using Xamarin 5.5.4 and encountering a strange problem I've never seen before: when I press one of the arrow keys it seems as if the shift keys, both left and right, are always considered to be NOT PRESSED, even if I press them.

I checked this with these lines of code inside my game loop:

        foreach (Keys key in Keyboard.GetState().GetPressedKeys()) {
            Console.WriteLine (key.ToString ());
        }

The output is always the same. When I press one of the shift keys only or first (and hold), I get

LeftShift
RightShift

Plus eventually the arrow keys (if shift was hold first). But when I press one of the arrow keys first and then press the shift key while one of the arrow keys is down, those two do not appear.

That's obviously a problem because my game character now cannot run when shift is pressed (at least when the arrow keys were pressed first and hold). I double checked if other keys like Z are also blocked, but it seems as if the arrow keys only block shift (but I haven't checked every key so far).

Does anyone know why this happens? I checked whether or not sticky keys is activated in Mac OSX, but it's not. Sadly, I couldn't find anything on the internet so far.

Any help is appreciated! Thanks a lot in advance!

I think MonoGame is doing a few special things to get certain keys to work on windows, might be some of these same fixes need to be done on other platforms.

Try locating the code in MonoGame that translates from OS key events to XNA key events. It is most likely where the problem is.

Also try running the most recent develop branch just to be sure it isn't a bug that was fixed in the mean time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM