At some point when Apple introduced the touchbar someone decided that you don’t need to truly turn it off… and it automatically turns on when you press a key. Meaning that you can’t cleanup the keyboard without draining the battery first. (I tried looking for undocumented configs to turn this off… for years -well more or less since 2017)
I used KeyboardCleanTool but it didn't worked for me. What it does is to put an app window that captures keyboard events, but you can still press certain keys (like a lock screen shortcut in the touch bar) to by-pass it. Many times what I did is to open vi in the terminal... and it does the same without the extra app.
At some point when Apple introduced the touchbar someone decided that you don’t need to truly turn it off… and it automatically turns on when you press a key. Meaning that you can’t cleanup the keyboard without draining the battery first. (I tried looking for undocumented configs to turn this off… for years -well more or less since 2017)