Update keylogrecorder.rb

Removed redundant code, added error checking.