where you have "<esc>" in your code, that generally means the ASCII character "Escape" similar to how you see "<cr>" for carriage return.
Try replacing that with 27 or $1B and see how you get on. (No difference between them except that 27 is decimal and $1B is hex.)
Bookmarks