简体   繁体   English

C#/ Monogame:Shift键被箭头键阻止了吗?

[英]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. 我目前正在使用Xamarin 5.5.4在Mac OSX 10.9.5的Monogame 3.2中编写游戏,遇到一个我从未见过的奇怪问题:当我按下其中一个箭头键时,似乎按住Shift键和右边的,即使我按了它们也总是被认为没有按下。

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 当我只按下一个或仅按住Shift键的一个时,我得到

LeftShift
RightShift

Plus eventually the arrow keys (if shift was hold first). 再加上箭头键(如果先按住Shift键)。 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. 但是,当我先按一个箭头键,然后在一个箭头键按下时按Shift键时,这两个键不会出现。

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). 显然这是一个问题,因为当按下shift键时(至少在先按住箭头键时),我的游戏角色现在无法运行。 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). 我仔细检查了是否也阻止了Z之类的其他键,但似乎箭头键只阻止了移位(但是到目前为止,我还没有检查所有键)。

Does anyone know why this happens? 有谁知道为什么会这样吗? I checked whether or not sticky keys is activated in Mac OSX, but it's not. 我检查了Mac OSX中是否激活了粘滞键,但没有激活。 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. 我认为MonoGame正在做一些特殊的事情来使某些键在Windows上工作,可能是在其他平台上需要做的一些相同的修复。

Try locating the code in MonoGame that translates from OS key events to XNA key events. 尝试在MonoGame中找到将OS按键事件转换为XNA按键事件的代码。 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. 还请尝试运行最新的developer分支,以确保它不是在此同时已修复的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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