切换Shift,Control和Alt键

时间:2011-12-06 00:01:11

标签: vb.net locking toggle shift

我已经能够使用下面的方法切换CAPS,NUM和SCROLL锁,但使用下面的代码,虽然单击按钮时没有出现任何错误,但没有任何反应?

适用于caps,num和scroll

的代码
Private Sub imgCONTROL_Click(sender As System.Object, e As System.EventArgs) Handles imgCONTROL.Click
    Call keybd_event(System.Windows.Forms.Keys.ControlKey, &H14, 1, 0)
    Call keybd_event(System.Windows.Forms.Keys.ControlKey, &H14, 3, 0)
End Sub

代码不起作用,请注意我已尝试过Alt,AltKey等的所有变体

Private Sub imgCONTROL_Click(sender As System.Object, e As System.EventArgs) Handles imgCONTROL.Click
    Call keybd_event(System.Windows.Forms.Keys.Alt, &H14, 1, 0)
    Call keybd_event(System.Windows.Forms.Keys.Alt, &H14, 3, 0)
End Sub

如果有人有解决方案,我将非常感激。

1 个答案:

答案 0 :(得分:0)

注意:此答案未经测试。这是对这个问题的快速刺激。

按下并释放它们时,CAPS,NUM和SCROLL锁定键会切换。

CTRL,ALT和SHIFT键在按下时打开,在释放时关闭。您的代码会立即按下并释放密钥。每次单击图像时,您都需要编写代码来切换密钥。

Private Sub imageALT_Click(sender As Object, e As EventArgs) Handles imgALT.Click
    ' Toggle key state to pressed or released.
    Dim Static State As Boolean = False
    State = Not State
    ' Set the flags to press or release.
    Dim Flags As Integer = 1 ' KEYEVENTF_EXTENDEDKEY
    If State Then Flags = Flags Or 2 ' KEYEVENTF_KEYUP
    ' Press or release the key.
    Call keybd_event(System.Windows.Forms.Keys.Alt, &H14, Flags, 0)
End Sub