How to get IsKeyDown method to work in C#

后端 未结 2 420
被撕碎了的回忆
被撕碎了的回忆 2020-12-11 22:42

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

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

The object browser says

2条回答
  •  盖世英雄少女心
    2020-12-11 23:17

    Add PresentationCore.dll assembly as a reference.

    Add WindowsBase.dll assembly as a reference.

    Test code:

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

提交回复
热议问题