This code existed to handle keys modifiers and special keys like `<C-w>` and `Space`. Your current code treats each character as a separate key.