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

查看:22
本文介绍了如何让 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:

public static bool IsKeyDown(System.Windows.Input.Key key)
System.Windows.Input.Keyboard
的成员总结:
确定是否按下了指定的键.
参数:
key: 指定的键.
返回值:
如果 key 处于 down 状态,则为 true;否则为假.

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.

好的,所以它是键盘的成员,对吗?我使用了以下代码:键盘测试 = new Keyboard();

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

但是当我输入 test 然后输入点时,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 程序集作为参考.

Add PresentationCore.dll assembly as a reference.

添加 WindowsBase.dll 程序集作为参考.

Add WindowsBase.dll assembly as a reference.

测试代码:

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天全站免登陆