Added smarter handling of shift states to incorporate CapsLock