如何捕捉 Ctrl + Alt + RShftKey [英] How to catch Ctrl + Alt + RShftKey
本文介绍了如何捕捉 Ctrl + Alt + RShftKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一段时间我试图在常见的 VBNET 键处理程序下捕获 Ctrl + Alt + Right Shift Key.这是我的测试:
For some time I'm trying to catch Ctrl + Alt + Right Shift Key under common VBNET key handler. Here are my tests:
If e.Control And e.Alt And e.KeyCode = Keys.Space Then
MsgBox("CTRL + ALT + SPACE") ' This work
End If
If e.Control And e.Shift And e.KeyCode = Keys.F10 Then
MsgBox("CTRL + SHIFT + F10") ' This work
End If
If e.Control And e.Alt And e.KeyCode = Keys.ShiftKey Then
MsgBox("CTRL + ALT + SHIFT") ' This work
End If
If e.Alt And e.Shift And e.KeyCode = Keys.LWin Then
MsgBox("ALT + SHIFT + LEFT WINDOWS") ' This work
End If
If e.Control And e.Alt And e.KeyCode = Keys.RShiftKey Then
MsgBox("CTRL + ALT + RIGHT SHIFT") ' This don't work
End If
Windows 7、WinForms、VB2008、NET 框架 2.0
Windows 7, WinForms, VB2008, NET framework 2.0
为什么我在描述的情况下无法抓住 Ctrl + Alt + Right Shift 键?
或者,我如何捕捉 Ctrl + Alt + Right Shift Key 组合?
Why I can't catch Ctrl + Alt + Right Shift Key in described situation?
Or, how do I catch Ctrl + Alt + Right Shift Key combination?
推荐答案
使用标准 VB.NET 方法无法检测 Shifts 之间的差异.为此,您必须连接到 Windows API:
There is no way to detect difference between Shifts using standard VB.NET approach. You will have to hook into Windows API for that:
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Private Shared Function GetAsyncKeyState(vKey As Keys) As Short
End Function
Private Sub Form2_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.Control And e.Alt And e.Shift Then
If Convert.ToBoolean(GetAsyncKeyState(Keys.LShiftKey)) Then
MsgBox("CTRL + ALT + LEFT SHIFT")
ElseIf Convert.ToBoolean(GetAsyncKeyState(Keys.RShiftKey)) Then
MsgBox("CTRL + ALT + RIGHT SHIFT")
End If
End If
End Sub
这篇关于如何捕捉 Ctrl + Alt + RShftKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文