I don't know how Keyboard Maestro does it, but you should be able to solve this issue by activating the option in iTerm 2: