Question

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...

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top