How to remap a key on my keyboard depending on whether it was quickly pressed or held down for a second or more?

I got myself a new keyboard (Keychron K6), and long story short, I’d like to have my Esc key only be mapped to Esc when I hold it for a second. If I just tap it like a normal keystroke, I need to have it be the backtick/tilde key instead.

So:

  • Press Esc: `~
  • Hold down Esc for a second: Esc

I’ve looked at the Keyboard Manager tool on PowerToys and also fiddled a bit with AutoHotKey, and both of them seem very powerful but none of them seem to be able to consider whether a key is being held down or briefly pressed.

Is this even possible?

Cheers!