TransWikia.com

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

Super User Asked by Fabio Bracht on December 3, 2020

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!

One Answer

Just tried this out, this AutoHotKey script should work

$esc::
 KeyWait,esc,T0.5 ;wait 0.5 seconds for release key
 If (ErrorLevel) ;more than 0.5 sec have passed
 {
  Send {esc}
  keyHeld = 1
  KeyWait,esc
 }
Return

$esc up::
 If (keyHeld = 0) ;If not held down
  Send ``
 Else
  keyHeld = 0
Return

shift & esc::
 Send ~
 keyHeld = 1
Return

Correct answer by rbits on December 3, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP