Harold Hunt - Morse Code Beeper 2009
Harold Hunt - Morse Code Beeper 2009
Morse Code Beeper 2009
I have just posted Morse Code Beeper 2009, a refresh of my original project from around 2004. Details on the new project are below.
Morse Code Beeper source code is licensed under an MIT-style license which can be obtained from the downloads page.
Morse Code Beeper was written in a mix of C (for the keyboard hook dll) and C++ (for the UI and beeper code) using some raw Win32 API calls and the Qt SDK.
Even if you don’t intend to contribute to the Morse Code Beeper project you can still browse the source code and get examples of a few techniques listed below. I appreciate either an email or a “tip” (a token amount is very much appreciated) if you find the examples beneficial for your learning or a project.
Win32 Techniques
•Installing a WH_KEYBOARD keyboard hook using SetWindowsHookEx and getting the messages back to another process (view a HWND-message) to perform an asynchronous action that can block on IO (or beeping in this case). Please don’t use this as the starting point of a keystroke logger. Note that your keyboard hook is injected into whatever application has the focus; therefore, a crash bug in your hook DLL will actually crash other applications on the system. The keyboard hook DLL in this code is quite stable from my testing and should be a sufficient starting point for other types of hook DLLs as well. In addition, the linked size of the DLL is only 6 KB.
Qt Creator/SDK Techniques
•QApplication::winEventFilter - Subclassing QApplication to override winEventFilter() to capture specific HWND messages from the Win32 message loop.
•QThread Signals/Slots - Properly getting a signal from one thread to invoke a slot on a QThread subclass on the thread that the QThread owns (oddly enough this doesn’t happen automatically as you might expect), as discussed in my blog post on QThread Signals/Slots.
•QSystemTrayIcon - Using a QSystemTrayIcon when the application has no actual main window.
•Qt/Win32 Integration Points - Setting up a .rc file with qmake to configure Win32 binary file Version information and icon.
•QSettings Non-Persistent Defaults - Wrapping QSettings with the concept of a “default” setting value that is not persisted. This prevents the case of a user opening your defaults popup, changing the value of one settings, then permanently getting a copy of the default value of every other setting at that time (which prevents you from bringing all users along if you later change the default for some setting from off to on; as they would have the old default of off saved).
•Qt Creator DLL Linking - The MorseCodeHook project has a post-build step that copies the output DLL for the debug or release build to the corresponding directory in the MorseCode project. For some reason this copying is not automatic and presence of the file in the MorseCode directories is required for that project to link. Even with a dependency setup between the projects this does not happen automatically and must be done with a manual cmd.exe build step as described in my blog post on Qt Creator.
Have Fun - Harold Hunt
Monday, August 24, 2009