Test if the Ctrl key is down using C#

后端 未结 6 1241
一整个雨季
一整个雨季 2020-12-01 09:59

I have a form that the user can double click on with the mouse and it will do something. Now I want to be able to know if the user is also holding the Ctrl key do

6条回答
  •  一向
    一向 (楼主)
    2020-12-01 11:02

    Just for completeness... ModifierKeys is a static property of Control, so you can test it even when you are not directly in an event handler:

    public static bool IsControlDown()
    {
        return (Control.ModifierKeys & Keys.Control) == Keys.Control;
    }
    

提交回复
热议问题