Click here to Skip to main content
13,552,737 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


78 bookmarked
Posted 10 Dec 2009
Licenced CPOL


, 3 Apr 2012
Rate this:
Please Sign up or sign in to vote.
Blinks keyboard LEDs to display network traffic.


I wanted to see the network activity other than in the system tray network icon, so I thought of using the keyboard's CAPS LOCK, SCROLL LOCK, and NUM key LEDs to display the network activity. TrafficLights is a simple application which blinks keyboard lights based on the network traffic on your computer. You can configure which light should blink on send or receive packets. It silently sits on your system tray. You can right click on TrafficLights' system tray icon to configure the LEDs or shut it down.


This is just to learn how to trap network traffic and control keyboard LEDs in .NET.

Using the Code

There are basically two parts to this application:

  • How to identify network traffic.
  • The code below is used to initialize the PerformanceCounter class instances - one for send and one for receive (namely m_performanceCounterSent and m_performanceCounterReceive). They are initialized like so:

    m_performanceCounterCategory = new PerformanceCounterCategory("Network Interface");
    string instance = m_performanceCounterCategory.GetInstanceNames()[0]; // 1st NIC !
    m_performanceCounterSent = new PerformanceCounter("Network Interface", 
                                   "Bytes Sent/sec", instance);
    m_performanceCounterReceived = new PerformanceCounter("Network Interface", 
                                       "Bytes Received/sec", instance);
  • How to control keyboard LEDs.
  • A background thread keeps running in the application, and it keeps on checking on the performance counter to check any network activity. And when an activity is detected, it blinks the configured keyboard LED.

    float fSentValue = m_performanceCounterSent.NextValue() / 1024;
    float fReceivedValue = m_performanceCounterReceived.NextValue() / 1024;
    if (fSentValue > 0)
       keybd_event((byte)m_sendLED, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
       keybd_event((byte)m_sendLED, 0x45, 
    if (fReceivedValue > 0)
       keybd_event((byte)m_receiveLED, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
       keybd_event((byte)m_receiveLED, 0x45, 

Points of Interest

As I mentioned earlier, it's a very simple application, but the intention was to learn how to trap network traffic in .NET.


This is the first version of this application. Also, my first attempt to post anything on CodeProject.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Amit Engineer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionNot sure it's a good idea. Pin
Member 30824879-Apr-12 22:03
memberMember 30824879-Apr-12 22:03 
QuestionStart menu Pin
AndreasJoh4-Apr-12 2:01
memberAndreasJoh4-Apr-12 2:01 
GeneralMy vote of 5 Pin
Abinash Bishoyi22-Mar-12 1:32
memberAbinash Bishoyi22-Mar-12 1:32 
GeneralGood C# copy Pin
Igor Tolmachev16-Jan-10 4:53
memberIgor Tolmachev16-Jan-10 4:53 
GeneralRe: Good C# copy Pin
Amit Engineer18-Jan-10 9:01
memberAmit Engineer18-Jan-10 9:01 
GeneralRe: Good C# copy Pin
tkrafael_net3-Apr-12 11:47
membertkrafael_net3-Apr-12 11:47 
Some simple ways to manipulate leds is through use of serial and parallel ports.

You could buy usb to serial and use its virtual serial device.
Using the Serial classes in .net, just write into its stream (remember that in serial ports, you can use only 8 bits, in which each pin is a wire and the ground is the last wire)
I did a small test long time ago with parallel and really works as expected.
GeneralNice and funny Pin
Muhammad Nauman Yousuf14-Dec-09 22:24
memberMuhammad Nauman Yousuf14-Dec-09 22:24 
GeneralNice but heavy CPU load Pin
Thomas Kuehn11-Dec-09 8:38
memberThomas Kuehn11-Dec-09 8:38 
GeneralRe: Nice but heavy CPU load Pin
Amit Engineer11-Dec-09 10:01
memberAmit Engineer11-Dec-09 10:01 
QuestionRe: Nice but heavy CPU load Pin
Amit Engineer11-Dec-09 10:11
memberAmit Engineer11-Dec-09 10:11 
AnswerRe: Nice but heavy CPU load Pin
Igor Tolmachev16-Jan-10 4:56
memberIgor Tolmachev16-Jan-10 4:56 
Generalgreat Pin
thebeekeeper11-Dec-09 4:57
memberthebeekeeper11-Dec-09 4:57 
Generalfunny.. [modified] Pin
reborn_zhang11-Dec-09 4:45
memberreborn_zhang11-Dec-09 4:45 
GeneralRe: funny.. Pin
reborn_zhang11-Dec-09 4:56
memberreborn_zhang11-Dec-09 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01-2016 | 2.8.180515.1 | Last Updated 3 Apr 2012
Article Copyright 2009 by Amit Engineer
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid