本文介绍了当两个键被同时按压检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何做到这一点。



我只知道如何检测一个键:

 私人无效Form1_KeyDown(对象发件人,发送KeyEventArgs E)
{
如果(e.KeyCode == Keys.C)
{
MessageBox.Show(C键);
}
}


解决方案

您必须跟踪的keydown / KEYUP事件,并保持所有目前向下的键的列表。键盘处理只能触发各个键,和它给你的代码来检测/跟踪哪些的是下降,如果这些个人的keydown事件是足够接近对方算作在一​​起。


I have no idea how do this.

I know only how do detect one key:

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.C)
    {
        MessageBox.Show("C key");
    }
}
解决方案

You have to keep track of keydown/keyup events, and keep a list of all the keys that are currently "down". The keyboard handler can only trigger on individual keys, and it's up to your code to detect/keep track of which ones are down, and if those individual keydown events are close enough to each other to be counted as "together".

这篇关于当两个键被同时按压检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:40