Use normal keys as modifier keys, e.g. press S and F together instead of Ctrl+S to save file

keyboardkeyboard shortcuts

Is there a way to use normal keys as modifier keys? Assuming my keyboard correctly records my pressing S and F together, is there a way for me to use the combination as a keyboard shortcut like Ctrl+S?

Specifically:

  • How do I test that my keyboard is capable of detecting simultaneous keypresses?
  • How can I remap the combination so that it can be used by an application like Emacs?

Best Answer

Q: How do I test that my keyboard is capable of detecting simultaneous keypresses?

A: You could use KeyCodes to monitor what Windows sees when pressing keyboard keys. In the picture below are three keys pressed simultaneously. OnKeyDown meens it's currently pressed and OnKeyUp triggers when you release the button.

enter image description here


Q: How can I remap the combination so that it can be used by an application like Emacs?

One possible way is to use AutoHotKey. I recommend the portable version of AutoHotKey to avoid the installation of additional software

The example shows how to remap key A to key B

A::SendInput {B}

It's also possible to add modifiers like Win(#), Alt(!), Ctrl(^) or Shift(+). Read the AHK manual section HotKeys for more info

+!A::SendInput {B}

Our main problem is that AHK cannot bind more than one base key. Base keys are all keyboard keys except modifier keys.

Luckily there is a trick. We only use S to trigger a small macro where we next check if F is pressed. If yes, we send our new key combination Ctrl+S

~S::
  GetKeyState, state, F
  if state = D
  SendInput ^{s} 
Return

~F::
  GetKeyState, state, S
  if state = D
  SendInput ^{s} 
Return
  • The downside is we have to do this for the other way around too where F is pressed first and then S
  • Don't forget the tilde ~ in front of a key which means the native function should not be blocked
  • Don't send an uppercase ^{S} or else AHK will send an additional Shift keystroke. I have no clue why. However, a lowercase ^{s} works as expected

Here is a AutoHotKey beginners guide on Youtube together with some useful links

Related Question