473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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:

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.     Private Sub e_KeyDown(ByVal sender As Object, _
  4.     ByVal e As KeyEventArgs)
  5.         ' If the 'E' key is pressed,
  6.         'plays 500 hertz sound for 50 milliseconds
  7.         If e.KeyCode = Keys.E Then
  8.             Console.Beep(500, 50)
  9.         End If
  10.     End Sub
  11.  
  12.  
  13.     Private Sub a_KeyDown(ByVal sender As Object, _
  14.        ByVal a As KeyEventArgs) Handles Button1.KeyDown
  15.  
  16.         If a.KeyCode = Keys.A Then
  17.             Console.Beep(650, 50)
  18.         End If
  19.     End Sub
  20.  
  21.  
  22.     Private Sub b_KeyDown(ByVal sender As Object, _
  23.        ByVal b As KeyEventArgs) Handles Button1.KeyDown
  24.  
  25.         If b.KeyCode = Keys.B Then
  26.             Console.Beep(200, 50)
  27.         End If
  28.     End Sub
  29.  
  30.     Private Sub c_KeyDown(ByVal sender As Object, _
  31.        ByVal c As KeyEventArgs) Handles Button1.KeyDown
  32.  
  33.         If c.KeyCode = Keys.C Then
  34.             Console.Beep(5020, 50)
  35.         End If
  36.     End Sub
  37.  
  38.     Private Sub d_KeyDown(ByVal sender As Object, _
  39.        ByVal d As KeyEventArgs) Handles Button1.KeyDown
  40.  
  41.         If d.KeyCode = Keys.D Then
  42.             Console.Beep(720, 50)
  43.         End If
  44.     End Sub
  45.  
  46.  
  47.     Private Sub f_KeyDown(ByVal sender As Object, _
  48.            ByVal f As KeyEventArgs) Handles Button1.KeyDown
  49.  
  50.         If f.KeyCode = Keys.F Then
  51.             Console.Beep(1000, 50)
  52.         End If
  53.     End Sub
  54.  
  55.     Private Sub g_KeyDown(ByVal sender As Object, _
  56.                ByVal g As KeyEventArgs) Handles Button1.KeyDown
  57.  
  58.         If g.KeyCode = Keys.G Then
  59.             Console.Beep(1280, 50)
  60.         End If
  61.     End Sub
  62.  
  63.     Private Sub h_KeyDown(ByVal sender As Object, _
  64.                   ByVal h As KeyEventArgs) Handles Button1.KeyDown
  65.  
  66.         If h.KeyCode = Keys.H Then
  67.             Console.Beep(1120, 50)
  68.         End If
  69.     End Sub
  70.  
  71.     Private Sub i_KeyDown(ByVal sender As Object, _
  72.                   ByVal i As KeyEventArgs) Handles Button1.KeyDown
  73.  
  74.         If i.KeyCode = Keys.I Then
  75.             Console.Beep(705, 50)
  76.         End If
  77.     End Sub
  78.  
  79.     Private Sub j_KeyDown(ByVal sender As Object, _
  80.                      ByVal j As KeyEventArgs) Handles Button1.KeyDown
  81.  
  82.         If j.KeyCode = Keys.J Then
  83.             Console.Beep(70, 50)
  84.         End If
  85.     End Sub
  86.  
  87.     Private Sub k_KeyDown(ByVal sender As Object, _
  88.                      ByVal k As KeyEventArgs) Handles Button1.KeyDown
  89.  
  90.         If k.KeyCode = Keys.K Then
  91.             Console.Beep(701, 50)
  92.         End If
  93.     End Sub
  94.  
  95.     Private Sub l_KeyDown(ByVal sender As Object, _
  96.                      ByVal l As KeyEventArgs) Handles Button1.KeyDown
  97.  
  98.         If l.KeyCode = Keys.L Then
  99.             Console.Beep(7095, 50)
  100.         End If
  101.     End Sub
  102.  
  103.     Private Sub m_KeyDown(ByVal sender As Object, _
  104.                      ByVal m As KeyEventArgs) Handles Button1.KeyDown
  105.  
  106.         If m.KeyCode = Keys.M Then
  107.             Console.Beep(848, 50)
  108.         End If
  109.     End Sub
  110.  
  111.     Private Sub n_KeyDown(ByVal sender As Object, _
  112.                      ByVal n As KeyEventArgs) Handles Button1.KeyDown
  113.  
  114.         If n.KeyCode = Keys.N Then
  115.             Console.Beep(605, 50)
  116.         End If
  117.     End Sub
  118.  
  119.     Private Sub o_KeyDown(ByVal sender As Object, _
  120.                      ByVal o As KeyEventArgs) Handles Button1.KeyDown
  121.  
  122.         If o.KeyCode = Keys.O Then
  123.             Console.Beep(712, 50)
  124.         End If
  125.     End Sub
  126.  
  127.     Private Sub p_KeyDown(ByVal sender As Object, _
  128.                      ByVal p As KeyEventArgs) Handles Button1.KeyDown
  129.  
  130.         If p.KeyCode = Keys.P Then
  131.             Console.Beep(2152, 50)
  132.         End If
  133.     End Sub
  134.  
  135.     Private Sub q_KeyDown(ByVal sender As Object, _
  136.                      ByVal r As KeyEventArgs) Handles Button1.KeyDown
  137.  
  138.         If r.KeyCode = Keys.R Then
  139.             Console.Beep(2012, 50)
  140.         End If
  141.     End Sub
  142.  
  143.     Private Sub r_KeyDown(ByVal sender As Object, _
  144.                      ByVal r As KeyEventArgs) Handles Button1.KeyDown
  145.  
  146.         If r.KeyCode = Keys.R Then
  147.             Console.Beep(201, 50)
  148.         End If
  149.     End Sub
  150.  
  151.     Private Sub s_KeyDown(ByVal sender As Object, _
  152.                      ByVal s As KeyEventArgs) Handles Button1.KeyDown
  153.  
  154.         If s.KeyCode = Keys.S Then
  155.             Console.Beep(101, 50)
  156.         End If
  157.     End Sub
  158.  
  159.     Private Sub t_KeyDown(ByVal sender As Object, _
  160.                      ByVal t As KeyEventArgs) Handles Button1.KeyDown
  161.  
  162.         If t.KeyCode = Keys.T Then
  163.             Console.Beep(7052, 50)
  164.         End If
  165.     End Sub
  166.  
  167.     Private Sub u_KeyDown(ByVal sender As Object, _
  168.                      ByVal u As KeyEventArgs) Handles Button1.KeyDown
  169.  
  170.         If u.KeyCode = Keys.U Then
  171.             Console.Beep(512, 50)
  172.         End If
  173.     End Sub
  174.  
  175.     Private Sub v_KeyDown(ByVal sender As Object, _
  176.                      ByVal v As KeyEventArgs) Handles Button1.KeyDown
  177.  
  178.         If v.KeyCode = Keys.V Then
  179.             Console.Beep(2502, 50)
  180.         End If
  181.     End Sub
  182.  
  183.     Private Sub w_KeyDown(ByVal sender As Object, _
  184.                      ByVal w As KeyEventArgs) Handles Button1.KeyDown
  185.  
  186.         If w.KeyCode = Keys.W Then
  187.             Console.Beep(725, 50)
  188.         End If
  189.     End Sub
  190.  
  191.     Private Sub x_KeyDown(ByVal sender As Object, _
  192.                      ByVal x As KeyEventArgs) Handles Button1.KeyDown
  193.  
  194.         If x.KeyCode = Keys.X Then
  195.             Console.Beep(1520, 50)
  196.         End If
  197.     End Sub
  198.  
  199.     Private Sub y_KeyDown(ByVal sender As Object, _
  200.                      ByVal y As KeyEventArgs) Handles Button1.KeyDown
  201.  
  202.         If y.KeyCode = Keys.Y Then
  203.             Console.Beep(1705, 50)
  204.         End If
  205.     End Sub
  206.  
  207.     Private Sub z_KeyDown(ByVal sender As Object, _
  208.                      ByVal z As KeyEventArgs) Handles Button1.KeyDown
  209.  
  210.         If z.KeyCode = Keys.Z Then
  211.             Console.Beep(711, 50)
  212.         End If
  213.     End Sub
  214.  
  215.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  216.  
  217.     End Sub
  218. 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.
Sep 2 '08 #1
1 1329
QVeen72
1,445 Expert 1GB
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
Sep 2 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
3
by: Greg Bryant | last post by:
I'm doing some work for a company that has an auction site running in coldfusion. They're not real happy with it, and it needs a major overhaul, so I'm looking at redoing it, and while I'm at it,...
4
by: pokémon | last post by:
Ok, I want to implmement a "backgound process", but the catch is this: I want to control it via a Web Service, that is to say, the Web Service will be its API. What type of application should...
0
by: Marian Dvorsky | last post by:
I would like to create an application that will be running in the background and will have an icon in the Notify bar in the lower-right corner of Windows desktop. For Windows NT+ I will probably...
6
by: Ganesh | last post by:
Is there a utility by microsoft (or anyone) to force garbage collection in a process without have access to the process code. regards Ganesh
1
by: Ed | last post by:
Is there a way to run an application in the background other than through a service. As I understand it when creating a service it is best practice not have any kind of user interface. My...
4
by: Mrinal Kamboj | last post by:
Hi , Doubt may be bit trivial , but i wanted to know , what are the exact benefits derived while we run a background process as an NT service in windows , we can as well achieve the...
5
by: David Lozzi | last post by:
Howdy, I wrote a web service in .Net for my customer. My customer has another vendor who now has to consume it but they are not using Visual Studio. Most of their pages are jsp, and they said...
13
by: giloosh99 | last post by:
Exec, shell_exec, system, popen functions all run the process in the background. how can i get it to run the process normally. my code looks like this: <? exec("batch_file.bat"); ?> am i...
5
by: Reddy | last post by:
I am running process.sart to run gpg.exe to encrypt files. It's working fine with console application. When i use same code in windows service. It's not working. It's not even throwing...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.