Nightcap Support

1. What is Nightcap?

Nightcap is a power saving utility that puts your Windows PC to sleep after a period of inactivity.

2. How does Nightcap work?

Nightcap quietly monitors any mouse or keyboard activity on your PC in order to determine when to put your computer to sleep. Once you stop interacting with your computer, Nightcap takes notice and after a prolonged period of inactivity, it displays a warning message that your computer is about to enter a deep state of rest. You can easily dismiss this message by moving your mouse or pressing a key.

3. Why Nightcap? – A Brief History

Your Windows Desktop uses a lot of power and having it on when no one is using it is wasteful and can make for costly power bills. So, you probably already have configured your PC to sleep by going into the Power Plans system settings, but perhaps you noticed that your Windows desktop stays awake regardless of what power options you choose or tweaks that you make.

That is what happened to me. I spent countless hours tweaking system settings and scouring forums for tips, but nothing worked. I would come into my office in the morning to find the naughty little machines, wide awake. Sometimes I would see my PCs powering down but then waking up moments later by an invisible force. I had enough and wanted to solve this problem once and for all. That is why I wrote Nightcap. Since I created Nightcap, my PCs are always in a sleep state when not in use.

Yes, but often these power settings “don’t take” and you spend hours of troubleshooting to figure why. Nightcap provides a better solution by putting your computer to sleep on time, every time. (See Why Night – Brief History).

8. Where can I go to provide feedback or get support?

For the past couple of weeks during the wee early morning hours before the kiddos wake, I have working on my latest pet-project, “Nightcap“. I thought that the program was mostly done. I should know by now to be more cautious of this mindset. I had been running Nightcap on my two Windows 8 PCs for months now without much ado, but when I took a closer look at the code base, I knew a couple of things needed changing before the much anticipated product release. My main concern was with the event-based approach that I used to detect keyboard and mouse activity. At first it appeared to work well, but during testing on our home PCs, my little beta testers (Thing 1 and Thing 2) noticed that their computers fell asleep while playing games. Clearly there was a lot of activity happening, but for some reason Nightcap had stopped noticing.

It turns out that Windows 8 was secretly unhooking my event monitors and replacing them with Folgers Crystals…

Well not actually that, but it might as well have. The net effect was that my app could no longer sense anything about the computer and that was kind of the whole point of Nightcap. Why did Windows have it in for my app? Perhaps Windows had deemed Nightcap a poor citizen of the OS? I did a little research and learned that in recent years Microsoft had discouraged event monitoring for programs like Nightcap for good reason. These event-hooking hogs can really slow a computer down. Microsoft recommends using Raw Input instead of events hooks because it doesn’t hamper system processes and provides a more efficient way to delivery device messages. Reading over the documentation, I could see that this approach was radically different than event hooking. Being so close to completing my app, I was desperate to find a quick-fix. Clearly, I wasn’t the first person to write an app that used event monitoring. I wasn’t thrilled about reworking the core of my app when it was 99% there. After a quick search, I learned about a workaround where you can fudge a registry setting to set the bar so low that no process, however laggy, would ever be unhooked. The “fix” worked, but the hack never sat well with me. I had sort of forgot about that workaround while I was in the final push to get Nightcap up on my website. Without this hack, I imagined thousands of computers inadvertently falling to sleep while folks were playing games or composing emails. Bottom line, this was no way to release Nightcap.

Which brings me to last week… I did some more research and decided that Raw Input processing was definitely the way to go even if I had to rewrite Nightcap. Unfortunately, the API was written for C++ and if I were to use it in my C# app, I would have to come up with a way to integrate the unmanaged code. Being new to C#, that was a learning process in itself, but I stuck with it and got the raw input code to work within Nightcap. However, after some initial testing, I noticed Nightcap had stopped responding to click events. Somehow the WM_INPUT handling was interfering with the normal event processing. After a few days of trying out various C++/C# incarnations without much luck, a new plan started to emerge. I thought,

“What if I separate out the event processing part of my app from the reporting and configuration piece?”

Eureka! I can write the input event monitoring as a Window Service and leave the C# app as-is. Only now, the visual aspect of Nightcap would interact with the behind scenes service to tell it under which circumstances to put the computer to sleep. The nice part about this approach is that the monitoring part of the program will be active even when no one is logged in. This comes in handy if your PC wakes up in the middle of the night because of LAN activity.

My blog has been neglected for the past couple of weeks, so I felt an update was in order. I hope to have a beta version of Nightcap on my website by May. As a side note, I really enjoy working with Microsoft tools once again. Visual Studio 13 is fun to work with and in my experience is the best programmer’s workbench in the industry. Debugging code is so well done and I really like how git has been integrated into the IDE. Nice work!

Is your Windows desktop an insomniac? Does your Windows PC stay awake no matter what you try? Maybe you’ve tried to adjust the Power Options in the control panel? Maybe you tweaked your LAN and USB device settings. Maybe you played around with the Powercfg utility? Maybe you tried all of the advice out there and still your PC won’t sleep. That has been my experience.

At home I have two custom-built PCs that use a lot of power. Inside these rigs I am running some pretty powerful video cards on 800W power supplies. My power bills were getting quite high and I was looking for ways to cut costs. I did not want my PCs running when nobody was using them. These are family computers that often get left on “by accident”. The problem for me was getting them to sleep. Windows has had power control settings since day one, but I have always had issues with this feature. Sometimes my PCs wouldn’t wake after going to sleep. Sometimes they would go to sleep at unexpected times without warning. But lately, my PCs just never went to sleep. I had hoped the issue was only happening on Windows 7 and that after I upgraded to Windows 8 things would improve, but they didn’t. I would schedule my computer to sleep after 20 minutes and began to notice the computer stayed awake. Sometimes my computer would sleep, but then immediately woke up for some reason. I researched the issue and learned that there were many things that could wake up a computer, from: shared media to USB devices. Here is one support link from Microsoft on how to troubleshoot the issue: http://support.microsoft.com/kb/976877

Determined to fix the issue once and for all, I would try solutions like the ones suggested in the support article, but after hours of tweaking, my PCs defiantly stayed awake. Just when I thought I had the computers down for the night, the little naughty PCs would wake themselves up again. Finally, I got fed up and came up with my own creative solution- I wrote an app called Nightcap that puts your PC to sleep after a specified period of time. Out of the box, Nightcap will put your computer to sleep after 10 minutes of inactivity. But the computer doesn’t just fall asleep without warning. A minute before sleeping, a warning will pop-up on screen with a countdown timer alerting you to the fact that your computer is about to sleep. To cancel the sleep state, simply move your mouse or press a key. Even cooler, the app can be set to fall right back to sleep if the computer has woken up without user interaction.

I had planned to make Nightcap available this weekend, but I wanted to ensure that the program provided a way for you to give feedback and report issues. Nightcap was developed on Windows 8, so I want to do some testing on Windows 7 and possibly XP.

If you have a sleepless PC and want such a program, please let me know and I’ll work extra hard to make it available on my site soon. My hope is that Nightcap will save you from hours of frustration and maybe even a little on your power bills. I know, for certain, it has saved money on mine.