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, _
    End If
End Sub

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


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.