We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,599 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

SendKeys.Send fails

When the code below is executed if sometimes it performs a "TAB" sometimes does nothing and sometimes gets my PC hung so I have to do CTR-ALT-DEL & Cancel which moves the execution of the program to the next line ("End IF"). Any idea what is missing to make it work? No special settings for mtComboBx

Private Sub myComboBx_KeyPress(ByVal sender As Object, ByVal e As     
   System.Windows.Forms.KeyPressEventArgs) Handles batch_typeComboBx.KeyPress
        If e.KeyChar = Chr(13) Then
            System.Windows.Forms.SendKeys.Send(Chr(9))
        End If
    End Sub
2
Contributors
4
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
5
Views
Question
Answered
radu_brasov
Newbie Poster
3 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Try this, you can send Enter as Tab and Enter + shift as Tab + Shift with it.

If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
            SendKeys.Send("{TAB}")
        Else
            If e.KeyCode = Keys.Enter Then
                SendKeys.Send("{TAB}")
        End If
End If
Gé48
Junior Poster in Training
63 posts since Apr 2010
Reputation Points: 11
Solved Threads: 10
Skill Endorsements: 0

I got the error 'KeyCode' is not a member of the System.Windows.Forms.KeyPressEventArgs.

Try this, you can send Enter as Tab and Enter + shift as Tab + Shift with it.

    If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
                SendKeys.Send("{TAB}")
            Else
                If e.KeyCode = Keys.Enter Then
                    SendKeys.Send("{TAB}")
            End If
    End If
radu_brasov
Newbie Poster
3 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Use KeyUp instead of KeyPress like this

Private Sub myComboBx_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles myComboBx.KeyUp

If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
SendKeys.Send("{TAB}")
Else
If e.KeyCode = Keys.Enter Then
SendKeys.Send("{TAB}")
End If
End If

End Sub

Gé48
Junior Poster in Training
63 posts since Apr 2010
Reputation Points: 11
Solved Threads: 10
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Gé48

Thank you for your efforts. Now it works both ways, with KeyCode and with KeyChar. It may have been setting Focus in 'Validating' event for the control that caused the malfunction.

Use KeyUp instead of KeyPress like this

Private Sub myComboBx_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles myComboBx.KeyUp

If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
SendKeys.Send("{TAB}")
Else
If e.KeyCode = Keys.Enter Then
SendKeys.Send("{TAB}")
End If
End If

End Sub

radu_brasov
Newbie Poster
3 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.1080 seconds using 2.66MB