.net difference between right shift and left shift keys

后端 未结 4 1257
陌清茗
陌清茗 2020-12-19 06:46

I am currently working on an application which requires different behaviour based on whether the user presses the right or left shift key (RShiftKey, LShiftKey), however whe

4条回答
  •  不知归路
    2020-12-19 07:13

    Take a look at the GetAsyncKeyState Win32 method. You can add a pInvoke call to it using:

    [DllImport("user32.dll")]
    private static extern short GetAsyncKeyState(Keys key);
    

    and then handle the KeyDown event on your form:

    private void MyForm_KeyDown(object sender, KeyEventArgs e)
    {
        Console.WriteLine("Left Shift :  " + (GetAsyncKeyState(Keys.LShiftKey) < 0));
        Console.WriteLine("Right Shift: " + (GetAsyncKeyState(Keys.RShiftKey) < 0));
    }
    

提交回复
热议问题