Toggleable and Per-App Key Remapping for Cross macOS-Windows Workflows
When switching between macOS and Windows keyboards, muscle memory inconsistencies can disrupt daily workflow. Two effective solutions exist to align key behaviors: a toggleable AutoHotkey (AHK) script for cross-system remapping, and a Karabiner Elements-based per-app automatic key switching setup.
Solution 1: AutoHotkey Toggleable Key Remapping
This script uses a global hotkey to switch between two remapping profiles, adjusting left Alt/Win keys and common shortcut behaviors to match either operating system.
; Toggle remapping mode with Ctrl+Win+Alt+M
^#!m::
keyRemapMode := (keyRemapMode = 1) ? 0 : 1
return
#if keyRemapMode = 1
; Mode 1: Swap left Alt and left Win for Mac-style modifier placement
lalt::rwin
lwin::ralt
#if
#if keyRemapMode = 0
; Mode 0: Default Windows modifier mapping
lalt::ralt
lwin::rwin
#if
; Remap Mac-style Alt shortcuts to Windows Ctrl equivalents
!c::Send ^c
!v::Send ^v
!x::Send ^x
!w::Send ^w
!z::Send ^z
+!z::Send ^y
!s::Send ^s
!l::Send ^l
!t::Send ^t
!a::Send ^a
!f::Send ^f
!r::Send ^r
!4::Send !{F4}
!/::Send ^/
; Map Alt+Left/Right to Home/End (matches macOS default navigation)
!left::Send {Home}
!right::Send {End}
!+left::Send +{Home}
!+right::Send +{End}
; Remap CapsLock to toggle input method
capslock::Send {Shift}
; Keychron Keyboard Customization: Remap Escape to Backspace
esc::Send {Backspace}
^esc::Send {Esc} ; Preserve original Ctrl+Esc functionality
!esc::Send {Asc 096} ; Map Alt+Esc to grave accent
!+esc::Send % "{ASC " . Asc("~") . "}"
; Remap grave key to Backspace for easier access
`::Send {Backspace}
!`::Send {Asc 096}
!+`::Send % "{ASC " . Asc("~") . "}"
; Remap Alt+CapsLock to Enter
!capslock::Send {Enter}
; Map Alt+1/2 to F1/F2 for screenshots and document renaming
!1::Send {F1}
!2::Send {F2}
!#1::Send {F1}
!#2::Send {F2}
!q::Send !{F1} ; Map Alt+Q to paste special functionality
; NOTE: This commented approach will not handle repeated key presses correctly
; !backspace::
; if (keyRemapMode) {
; SendInput {LWin Down}
; } else {
; SendInput {LAlt Down}
; }
; return
; lalt::lwin ; Uncomment to use Mac-style left Alt mapping on physical Mac keyboard
; lwin::lalt ; Uncomment to swap left Win and Alt directly
Solution 2: Karabiner Elements Per-App Auto Remapping
This method uses Karabiner Elements to automatically apply key mappings based on the active application, eliminating the need for manual toggling. Note that brew-based installation may fail on newer macOS versions like Ventura; alternative installation steps are widely available online.
The setup process follows three core steps:
- Instal Karabiner Elements
- Install the Karabiner background switching service
- Create and apply per-app profile configurations, then log out and back in to fully apply changes.
Below is a sample Karabiner configuraton that blocks unwanted Cmd+W and Cmd+Q shortcuts, remapping them to Mission Control instead:
{
"description": "Block Cmd+W and Cmd+Q, remap to Mission Control",
"manipulators": [
{
"from": {
"key_code": "q",
"modifiers": {
"mandatory": "left_command"
}
},
"to": [
{
"apple_vendor_keyboard_key_code": "mission_control"
}
],
"type": "basic"
},
{
"from": {
"key_code": "w",
"modifiers": {
"mandatory": "left_command"
}
},
"to": [
{
"apple_vendor_keyboard_key_code": "mission_control"
}
],
"type": "basic"
}
]
}
Reference: Original guide from https://notes.mengxin.science/2018/09/08/Switch-keys-for-specific-application-on-mac-os/