From 2c6e943a89f6f5e978b9de1e1b919c52ccca1c08 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 9 Mar 2024 18:21:26 -0500 Subject: [PATCH] Allow unbinding keys by pressing the same key. This is useful if you want to remove the "start chat" binding. --- Scripts/Python/xOptionsMenu.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Scripts/Python/xOptionsMenu.py b/Scripts/Python/xOptionsMenu.py index f2b04f5a45..855dd7e327 100644 --- a/Scripts/Python/xOptionsMenu.py +++ b/Scripts/Python/xOptionsMenu.py @@ -1810,8 +1810,12 @@ def ISetKeyMapping(self, controlCodeId: int, vkey: int, modifiers: int, isPrimar km = ptKeyMap() newKeyStr = km.convertVKeyToChar(vkey, modifiers) - # This will cause any previous uses of the key to be unbound. + # If this is the same key as before, unmap the binding. controlCode = kControlCodes[controlCodeId] + if self.IGetBoundKey(controlCode, keyIdx=0 if isPrimary else 1) == newKeyStr: + newKeyStr = "(unmapped)" + + # This will cause any previous uses of the key to be unbound. if isinstance(controlCode, str): PtDebugPrint(f"xOptionsMenu.ISetKeyMapping(): Binding {newKeyStr=} to console command {controlCode=}") km.bindKeyToConsoleCommand(newKeyStr, controlCode)