none
keybd_Event CTRL and ALT not releasing unless clicking out of window RRS feed

  • Question

  • Const KEYEVENTF_EXTENDEDKEY = &H1
    Const KEYEVENTF_KEYUP = &H2

    If random_variable_name = 1 then

    keybd_event(Keys.LControlKey, 0, KEYEVENTF_EXTENDEDKEY, 0) KB_Learn_Textbox.Text = My.Computer.Keyboard.CtrlKeyDown

    else

    While My.Computer.Keyboard.CtrlKeyDown keybd_event(Keys.LControlKey, 0, KEYEVENTF_KEYUP, 0) KB_Learn_Textbox.Text = My.Computer.Keyboard.CtrlKeyDown End While

    end if

    Hello, This is a sample of the code i am using.

    The textbox.text would state the ctrlkeydown  = false but any action i do still keeps control key down

    I will have to click out of the current active window to actually have this "keyup" action kick in.

    what i am doing wrong?

    thanks



    • Edited by dodindaga Monday, August 7, 2017 12:19 AM
    Monday, August 7, 2017 12:08 AM

Answers

  • thanks.. the main gist i got from it was not to use "KEYEVENTF_EXTENDEDKEY"

    keybd_event(Keys.LControlKey, 0, 0, 0) 'keydown'
    keybd_event(Keys.LControlKey, 0, KEYEVENTF_KEYUP, 0) 'key up '

    this worked... thanks

    • Marked as answer by dodindaga Monday, August 7, 2017 12:54 AM
    Monday, August 7, 2017 12:54 AM

All replies

  • Apparently similar problem to this recent thread
    Monday, August 7, 2017 12:32 AM
  • thanks.. the main gist i got from it was not to use "KEYEVENTF_EXTENDEDKEY"

    keybd_event(Keys.LControlKey, 0, 0, 0) 'keydown'
    keybd_event(Keys.LControlKey, 0, KEYEVENTF_KEYUP, 0) 'key up '

    this worked... thanks

    • Marked as answer by dodindaga Monday, August 7, 2017 12:54 AM
    Monday, August 7, 2017 12:54 AM
  • Hi

    Not entirely sure what you want, but is this of any help?

    ' blank Form1
    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim this As Integer = 1
        Dim TextBox1 As New TextBox
        Dim Timer1 As New Timer
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            With TextBox1
                .Location = New Point(20, 20)
                .Width = 100
            End With
            Controls.Add(TextBox1)
            With Timer1
                .Interval = 40
                .Enabled = True
            End With
            AddHandler Timer1.Tick, AddressOf Timer1_Tick
        End Sub
        Private Sub Timer1_Tick(sender As Object, e As EventArgs)
            If this = 1 Then
                TextBox1.Text = CType(IIf(My.Computer.Keyboard.CtrlKeyDown, "True", "false"), String)
            End If
        End Sub
    End Class
    


    Regards Les, Livingston, Scotland

    Monday, August 7, 2017 1:23 AM