 |

September 2nd, 2008, 03:54 AM
|
|
Newbie
|
|
Join Date: Sep 2008
Posts: 1
|
|
Background Process/Service in MS VB 2006 Express
Ok I made a Windows Applications that makes the computer beep at a certain frequency when you press a letter key. Problem is, it doesn't do anything when it i out of focus. How do I make it continue to beep whether it is in focus or not. Here is the code:
Code:
Public Class Form1
Private Sub e_KeyDown(ByVal sender As Object, _
ByVal e As KeyEventArgs)
' If the 'E' key is pressed,
'plays 500 hertz sound for 50 milliseconds
If e.KeyCode = Keys.E Then
Console.Beep(500, 50)
End If
End Sub
Private Sub a_KeyDown(ByVal sender As Object, _
ByVal a As KeyEventArgs) Handles Button1.KeyDown
If a.KeyCode = Keys.A Then
Console.Beep(650, 50)
End If
End Sub
Private Sub b_KeyDown(ByVal sender As Object, _
ByVal b As KeyEventArgs) Handles Button1.KeyDown
If b.KeyCode = Keys.B Then
Console.Beep(200, 50)
End If
End Sub
Private Sub c_KeyDown(ByVal sender As Object, _
ByVal c As KeyEventArgs) Handles Button1.KeyDown
If c.KeyCode = Keys.C Then
Console.Beep(5020, 50)
End If
End Sub
Private Sub d_KeyDown(ByVal sender As Object, _
ByVal d As KeyEventArgs) Handles Button1.KeyDown
If d.KeyCode = Keys.D Then
Console.Beep(720, 50)
End If
End Sub
Private Sub f_KeyDown(ByVal sender As Object, _
ByVal f As KeyEventArgs) Handles Button1.KeyDown
If f.KeyCode = Keys.F Then
Console.Beep(1000, 50)
End If
End Sub
Private Sub g_KeyDown(ByVal sender As Object, _
ByVal g As KeyEventArgs) Handles Button1.KeyDown
If g.KeyCode = Keys.G Then
Console.Beep(1280, 50)
End If
End Sub
Private Sub h_KeyDown(ByVal sender As Object, _
ByVal h As KeyEventArgs) Handles Button1.KeyDown
If h.KeyCode = Keys.H Then
Console.Beep(1120, 50)
End If
End Sub
Private Sub i_KeyDown(ByVal sender As Object, _
ByVal i As KeyEventArgs) Handles Button1.KeyDown
If i.KeyCode = Keys.I Then
Console.Beep(705, 50)
End If
End Sub
Private Sub j_KeyDown(ByVal sender As Object, _
ByVal j As KeyEventArgs) Handles Button1.KeyDown
If j.KeyCode = Keys.J Then
Console.Beep(70, 50)
End If
End Sub
Private Sub k_KeyDown(ByVal sender As Object, _
ByVal k As KeyEventArgs) Handles Button1.KeyDown
If k.KeyCode = Keys.K Then
Console.Beep(701, 50)
End If
End Sub
Private Sub l_KeyDown(ByVal sender As Object, _
ByVal l As KeyEventArgs) Handles Button1.KeyDown
If l.KeyCode = Keys.L Then
Console.Beep(7095, 50)
End If
End Sub
Private Sub m_KeyDown(ByVal sender As Object, _
ByVal m As KeyEventArgs) Handles Button1.KeyDown
If m.KeyCode = Keys.M Then
Console.Beep(848, 50)
End If
End Sub
Private Sub n_KeyDown(ByVal sender As Object, _
ByVal n As KeyEventArgs) Handles Button1.KeyDown
If n.KeyCode = Keys.N Then
Console.Beep(605, 50)
End If
End Sub
Private Sub o_KeyDown(ByVal sender As Object, _
ByVal o As KeyEventArgs) Handles Button1.KeyDown
If o.KeyCode = Keys.O Then
Console.Beep(712, 50)
End If
End Sub
Private Sub p_KeyDown(ByVal sender As Object, _
ByVal p As KeyEventArgs) Handles Button1.KeyDown
If p.KeyCode = Keys.P Then
Console.Beep(2152, 50)
End If
End Sub
Private Sub q_KeyDown(ByVal sender As Object, _
ByVal r As KeyEventArgs) Handles Button1.KeyDown
If r.KeyCode = Keys.R Then
Console.Beep(2012, 50)
End If
End Sub
Private Sub r_KeyDown(ByVal sender As Object, _
ByVal r As KeyEventArgs) Handles Button1.KeyDown
If r.KeyCode = Keys.R Then
Console.Beep(201, 50)
End If
End Sub
Private Sub s_KeyDown(ByVal sender As Object, _
ByVal s As KeyEventArgs) Handles Button1.KeyDown
If s.KeyCode = Keys.S Then
Console.Beep(101, 50)
End If
End Sub
Private Sub t_KeyDown(ByVal sender As Object, _
ByVal t As KeyEventArgs) Handles Button1.KeyDown
If t.KeyCode = Keys.T Then
Console.Beep(7052, 50)
End If
End Sub
Private Sub u_KeyDown(ByVal sender As Object, _
ByVal u As KeyEventArgs) Handles Button1.KeyDown
If u.KeyCode = Keys.U Then
Console.Beep(512, 50)
End If
End Sub
Private Sub v_KeyDown(ByVal sender As Object, _
ByVal v As KeyEventArgs) Handles Button1.KeyDown
If v.KeyCode = Keys.V Then
Console.Beep(2502, 50)
End If
End Sub
Private Sub w_KeyDown(ByVal sender As Object, _
ByVal w As KeyEventArgs) Handles Button1.KeyDown
If w.KeyCode = Keys.W Then
Console.Beep(725, 50)
End If
End Sub
Private Sub x_KeyDown(ByVal sender As Object, _
ByVal x As KeyEventArgs) Handles Button1.KeyDown
If x.KeyCode = Keys.X Then
Console.Beep(1520, 50)
End If
End Sub
Private Sub y_KeyDown(ByVal sender As Object, _
ByVal y As KeyEventArgs) Handles Button1.KeyDown
If y.KeyCode = Keys.Y Then
Console.Beep(1705, 50)
End If
End Sub
Private Sub z_KeyDown(ByVal sender As Object, _
ByVal z As KeyEventArgs) Handles Button1.KeyDown
If z.KeyCode = Keys.Z Then
Console.Beep(711, 50)
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Any ideas? I've heard you need to tell it to continue even when not in focus. How do I do this? This is for a harmless prank, but nothing dangerous.
|

September 2nd, 2008, 07:55 AM
|
 |
Moderator
|
|
Join Date: Oct 2006
Location: Bangalore
Posts: 1,283
|
|
Hi,
You dont have to write so many Sub Procedures for each Key..
First make Form's property KeyPreview=True,
and in Form's Key Down or Key press, Use a Select Case to Find out the Key, and Fire the beep..
If done for Form, it will automatically fire for all the control's key press...
Regards
Veena
|
 |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|