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

后端 未结 4 1866
温柔的废话
温柔的废话 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 10:08

    Since you're writing a game, it might be helpful to also use DirectInput... Winforms isn't really meant for da gaimez IMO...

    Device di_device = new Device(SystemGUID.Keyboard);
    di_device.SetCooperativeMode(Nonexclusive|othercrap);
    di_device.Acquire();
    
    if(di_device.GetKeyboardState()[Keys.LControl])
    {
        blargh;
    }
    

    Code written in SO textbox, untested, something like that. Note that you must include Microsoft.DirectX.DirectInput

    Also note that i don't mean you should init a DirectInput device every time you need to get input. Create the device when you init your game, dispose of it when your program exits.

    DirectInput gives you more control... And chances are, you're going to want to use it. Of course at certain points, you will need to use Winforms instead [ie: while your program is rendering, what if the user presses a button pretty quickly? GKS won't tell you about it]

提交回复
热议问题