开发者

Capturing a shift+tab keypress in C#

I'm trying to capture shift + tab in c# using t开发者_StackOverflow中文版he following cpp syntax:

if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
{
   // The key is currently down
}

Can anyone point me to the c# equivalent?

Thanks, Drew


The syntax is almost exactly the same.

You'll need to declare the GetAsyncKeyState method like this:

[DllImport("user32.dll")]
static extern int GetAsyncKeyState(System.Windows.Forms.Keys vKey); 

Instead of VK_SHIFT, you can write Keys.Shift

Also, C# doesn't impicitly convert int to bool, so you'll need to compare that to 0.

Therefore, you'll need to write

if ((GetAsyncKeyState(Keys.Shift) & 0x8000) != 0)

However,

You can do this without P/Invoke by checking Control.ModifierKeys.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜