Can you disable the quit game function with Esc key?

It seems that if I use the Keyboard actuator with the Esc key, it overwrites the function.
But I mainly use Python and when I write a function for the Esc key, it won’t overwrite the function and end the game.
Is there any way how to disable this function?

just change it to something else. i like the pause/break key.

1 Like

in general setup assign exit key not equal esc or assign empty key button, and use bge.logic.endGame(), if you need end game. In python keyboard events/inputs support all keys

1 Like

What I have found out is, if I assign anything like sending a message through an actuator in logic bricks it overwrites the quit game function, and then I can write a new function for the Esc key with python.
But I don’t know if this is the best way but it works.

if method work for game and simply and understand and not calling errors - this good choice

1 Like

If you want a way to completely remove any exit-key input, here’s a method that I use to allow only menu exiting or OS force software closing methods:

import bge
bge.logic.setExitKey(bge.events.ESCKEY == 2)
1 Like

Can you change the Esc key function afterward if you disable this?

Absolutely. Here’s a full blend file demonstrating the code technique.
Click the SPACE key to toggle whether the quit-key is locked or unlocked.

import bge

def main(self):
    
    if self.owner["Lock"] == True:
        bge.logic.setExitKey(0)
    elif self.owner["Lock"] == False:
        bge.logic.setExitKey(bge.events.ESCKEY)
    if bge.logic.keyboard.events[bge.events.SPACEKEY] == 1:
        self.owner["Lock"] = not self.owner["Lock"]

Blend

BGE_Toggle_Quit_Input.blend (90.2 KB)

1 Like

Works great, thank you.

1 Like