如何在按下任意键检测 [英] How to detect if any key is pressed

查看:126
本文介绍了如何在按下任意键检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能检测是否正在按任何键盘按键?我不感兴趣的关键是什么,我只是想知道是否有键仍然按下。

 如果( Keyboard.IsKeyDown(Key.ANYKEY?)
{

}


解决方案

 公共静态的IEnumerable<关键> KeysDown()
{
的foreach(主要在Enum.GetValues​​键(typeof运算(关键)))
{
如果(Keyboard.IsKeyDown(密钥))
产量返回键;
}
}

然后你可以这样做:

 如果(KeysDown()。任何())// ... 


How can I detect if any keyboard key is currently being pressed? I'm not interested in what the key is, I just want to know if any key is still pressed down.

if (Keyboard.IsKeyDown(Key.ANYKEY??)
{

}

解决方案

public static IEnumerable<Key> KeysDown()
{
    foreach (Key key in Enum.GetValues(typeof(Key)))
    {
        if (Keyboard.IsKeyDown(key))
            yield return key;
    }
}

you could then do:

if(KeysDown().Any()) //...

这篇关于如何在按下任意键检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆