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

Focus on KeyDown?

I have seen similar questions which attempt to solve this issue, but none seem to work for me so far...

Basically, for my first VB project, I am creating a virtual keyboard where a sound is played from the resources on KeyDown. So far, the program seems to work except for the fact that each key needs to be clicked by the mouse before the sound is played by pressing each key (hence put the object in focus), where I need the key to play the sound without clicking the keyboard key (put the object in focus on KeyDown). Below is an example of my code:

Private Sub C_KeyDown(ByVal sender As System.Object, ByVal e As PreviewKeyDownEventArgs) Handles C.PreviewKeyDown ' C is the label attached to the first 'Rectangle' (Key)
    If (e.KeyCode = Keys.A) Then 'The A key should activate the C key on the keyboard 
        My.Computer.Audio.Play(My.Resources.C, _
                                   AudioPlayMode.Background)
    End If
End Sub

I have KeyPreview set to 'True' under the form's properties.

Thanks

1
Contributor
1
Reply
56 Minutes
Discussion Span
1 Year Ago
Last Updated
2
Views
Question
Answered
Mwoot
Newbie Poster
2 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Mwoot
Newbie Poster
2 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 1 Year Ago

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.0596 seconds using 2.64MB