Can I determine whether a Ctrl key press is Left Ctrl or Right Ctrl?

后端 未结 4 1865
温柔的废话
温柔的废话 2021-01-16 09:24

I want to determine whether a CTRL key is LEFT CTRL or RIGHT CTRL key when it is pressed. How can I do this?

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-16 09:45

    Apparently not from within .NET, but it's possible from the Win32 APIs.

    • The System.Windows.Forms.Key enumeration tracks left, right, and middle mouse buttons, but only has one flag for Control keys, so no way to determine left or right for Control keys.
    • The Console.ReadKey() method suffers from the same problem.
    • You might be able to do something at the Win32 level. The WM_KEYDOWN message will track the extended keys (right Alt, right Control), so Windows is tracking this data ... it just isn't being passed on to .NET. You're on your own with regard to tapping into the Win32 API from within .NET.

提交回复
热议问题