The Esc key bug in games with the CJK IMEs
Recently, I’ve been playing through a really old shooter game named “Spec Ops: The Line”. Being a very old game, it has a bunch of weird quirks, such as some parts of the game being tied to the frame rate and being impossible to beat if you have a high refresh rate monitor, or the fullscreen mode completely screwing up the resolutions of the secondary monitors, etc.
But one bug that has seriously nagged me is that I can’t pause the game. Whenever I press the Esc key to bring up the pause menu, the pause menu flashes for a quarter of a second and then blinks out again. The only workaround I found was to Alt-Tab out of the game, then Alt-Tab back in, then quickly hit the Esc key twice while the game redrew onto the screen.
Unfortunately, you can’t really save and quit the game without going through the pause menu, so I tried to figure out what was going on. For some reason, I couldn’t find much information about it online. Given that SOTL had a recent surge of eyeballs on it when it was delisted from Steam, I knew that if it was a widespread issue then people must have posted about it online. The fact that there wasn’t any coverage about it, as far as I could tell, told me that it was a quirk with how the game interacted with my environment and system.
I first tried unplugging all external keyboards and mice, in case Windows was doing something weird with multiple input devices. That didn’t help. I then tried switching my input method editor from Korean to English, and that immediately fixed it. Wait, what?
So I looked online, and it seems this affects other games, too:
But why? I don’t know, but here is my best guess:
With a CJK (Chinese, Japanese, Korean) IME (input method editor), the editor must chain together a series of keypresses that the user inputs to write a single character, unlike other languages like English. For example, to type the Korean letter 가, you press the “r” key and the “k” key on the keyboard, but you get one character on the screen.
So how does the IME know whether the user meant to type 가, or ㄱ and ㅏ separately? One way that users can do this is to press the escape key after pressing the first key. This tells the IME to return to the alpha character input mode, awaiting the first keypress for the next string of keypresses to construct another character.
My hunch is when the IME emits the event for the Esc key, it also emits the event that lets the program running that it has returned to this state that awaits the alpha character input. This would allow programs to stop displaying the underline under the character being currently modified, to let the user know that successive keypresses will be interpreted as a new character. For game engines that are listening for the Esc key, they interpret it as two presses on the Esc key in succession, even though the Esc key has been pressed only once.
Unfortunately, I could not reproduce this with other keycode capturing software like KeyboardStateView for Windows, so it might just be a case of bad game engine code in some games where they never thought to test it on CJK IMEs. A pretty strange bug!