Refactored key capture code and converted into a class library.