1.11M Members

Focus on KeyDown?

 
0
 

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

Question Self-Answered as of 2 Years Ago
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: