如何获得IsKeyDown方法在C#中工作 [英] How to get IsKeyDown method to work in C#

查看:695
本文介绍了如何获得IsKeyDown方法在C#中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何得到这个方法的工作:

I can’t figure out how get this method to work:

System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key)

对象浏览器说以下内容:

The object browser says the following:

公共静态布尔IsKeyDown(System.Windows.Input.Key键)结果
System.Windows.Input.Keyboard结果
成员的摘要:结果
确定指定的键是否被按下结果
参数:结果
键:指定的关键结果
返回值:结果
真,如果关键是在下降州;否则为false。

public static bool IsKeyDown(System.Windows.Input.Key key)
Member of System.Windows.Input.Keyboard
Summary:
Determines whether the specified key is pressed.
Parameters:
key: The specified key.
Return Values:
true if key is in the down state; otherwise, false.

好吧,所以它的键盘中的一员,对不对?我用下面的代码:
键盘测试=新键盘();

Okay, so it’s a member of Keyboard, right? I used the following code: Keyboard test = new Keyboard();

但是,当我键入测试,然后点,IsKeyDown是不是一种选择。唯一的选择是从Windows.Forms的成员。我缺少的是在这里吗?谢谢你。

But when I type test and then the dot, IsKeyDown is not an option. The only options are from the Windows.Forms members. What am I missing here? Thanks.

推荐答案

添加 PresentationCore.dll中装配作为参考。

添加 WindowsBase.dll中装配作为参考。

测试代码:

private void buttonMisc_Click(object sender, EventArgs e)
{
    if (System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.LeftShift) == true)
        MessageBox.Show("Got it!");
}

这篇关于如何获得IsKeyDown方法在C#中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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