How can I cancel a dialog with the ESC key?

Hello,
I would like to have a feature in my game that allows me to immediately terminate the event process by pressing the ESC key. This should be used to cancel a conversation if the player no longer wants to continue it. I would really appreciate it if someone could help me.

greetings Ombladje
Are you sure you really want this? The consequences will be that all things you put into event like turning on/off switches, giving items, battle processing would get cancelled too.

EDIT: and ESC already cancels the 1 instance of show text.
Yes, I want it. There is no combat system in my game, only dialogues. It's a short game where this feature would be really cool. You can talk to characters multiple times to solve a puzzle. It would be practical if something comes to mind in the middle of a conversation and you can cancel the dialogue.
What I mean is that even if you make your puzzle it would be cancellable by esc, so one can overcome the puzzle maybe this way.

The way you could approach it without plugin is to split conversations to smaller chunks and break them with a choices to start another conversation or to exit.
That's okay, it will still work in my game. You just have to read a lot, and there are no switches or anything in the conversation.

The way you could approach it without plugin is to split conversations to smaller chunks and break them with a choices to start another conversation or to exit.
That would be very cumbersome and would probably be annoying.
You can try creating new file <name>.js and pasting the simple plugin code, then put the file into JS/Plugins folder and add it via plugin manager.
Spoiler: Simple Plugin
JavaScript:
_game_Interpreter_update = Game_Interpreter.prototype.update;
Game_Interpreter.prototype.update = function() {
    if(Input.isPressed("escape")) {
        this.terminate();
    } else {
        _game_Interpreter_update.call(this);
    }
};
it doesn't work, the game stops when I press ESC :/
I tested it in RPG Maker MZ and it was working, could you share your project where it is not working?
Ah, okay, now I understand what the issue is. It works for me too, except when the conversation is running through Common Events. Would it be possible to make that work as well? That would be perfect.
Ah, yes it stops the game when used for the common event. I'll work on this but tomorrow.
okey thank you very much
I updated the plugin to not crash the game.
Spoiler: Updated Plugin
JavaScript:
_game_map_updateInterpreter = Game_Map.prototype.updateInterpreter;
Game_Map.prototype.updateInterpreter = function() {
    if(Input.isPressed("escape")) {
        this._interpreter.terminate();
    }
    else {
        _game_map_updateInterpreter.call(this);
    }
};

It works with normal common events. As for common and ordinary events which are set to autorun it is dangerous because in such events you would set switch at the end to prevent event running endlessly. That switch will be skipped and the event just restarts.
Thank you, it works well. I will mention you in the credits 🙂

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-cancel-a-dialog-with-the-esc-key.176342/