shift pressed, and automatically up?(to avoid long press and hold)

守給你的承諾、 提交于 2019-12-13 06:49:56

问题


Some help on... how to make it possible when shift is pressed,

then the system automatically released it in split second,

hence even though it is still pressed in the keyboard by the user,

but the vb.net system already released the shift key?

to avoid long press or hold on the key...


I'm so out of idea already, hence decided to post a question here after doing some serious researches, please respond if you know some tricks to make this possible...


回答1:


You can handle KeyDown event and check if Shift is pressed.

e.KeyCode = Keys.Shift

You can work with user32.dll lib and send the key release. &H10 is Shift key code. Here is a list of all key codes (replace 0x with &H). &H2 means release. Type &H0 if you want to press.

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)

keybd_event(&H10, 0, &H2, 0)

You may want to handle entire form's KeyDown events.

Form.KeyPreview = True

Here is an example.

Public Class Form1
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)

    Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Me.KeyPreview = True
    End Sub

    Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Shift Then
            Form1.keybd_event(&H10, 0, &H2, 0)
        End If
    End Sub
End Class


来源:https://stackoverflow.com/questions/23594758/shift-pressed-and-automatically-upto-avoid-long-press-and-hold

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!