Skip to content

Instantly share code, notes, and snippets.

@ascendbruce
Last active September 8, 2024 02:58
Show Gist options
  • Save ascendbruce/677c3169259c975259045f905cd889d6 to your computer and use it in GitHub Desktop.
Save ascendbruce/677c3169259c975259045f905cd889d6 to your computer and use it in GitHub Desktop.
Use macOS-style shortcuts in Windows

Use macOS-style shortcuts in Windows / keyboard mappings using a Mac keyboard on Windows

ℹ️ There is a newer alternative project that does similar things and more, check it out at https://github.com/stevenilsen123/mac-keyboard-behavior-in-windows

Make Windows PC's shortcut act like macOS (Mac OS X) (using AutoHotkey (ahk) script)

With this AutoHotKey script, you can use most macOS style shortcuts (eg, cmd+c, cmd+v, ...) on Windows with a standard PC keyboard.

How does it work

Here's some examples of how this script work:

you want to press what you're actually pressing AutoHotKey tells Windows
cmd + c alt + c ctrl + c
cmd + v alt + v ctrl + v
cmd + r alt + r F5
cmd + ↑ alt + ↑ Home
cmd + shift + [ alt + shift + [ ctrl + shift + Tab
... ... ...

Note that:

  1. you shouldn't change the modifier keys mapping with keyboard DIP. This script assumes you (1) use a PC keyboard on Mac and have swapped [cmd] and [option] keys via Mac system preferences (2) you are familiar with mac shortcuts in macs (3) you want to use the PC keyboard and mac-style shortcuts on PC.
  2. To use cmd + shift + ↑ / ↓ / ← / → (select text between cursor and top / bottom / beginning of line / end of line), You should disable the Between input languages shotcut from Control Panel\Clock, Language, and Region\Language\Advanced settings > Change lanugage bar hot keys due to conflicting.
  3. Some Windows built-in keyboard shortcuts will be overridden. For example: win + ↑ / ↓ / ← / → (snap window to side). Change mac.ahk accordingly if you prefer to keep the default behavior.

To Run Once (until reboot)

  1. Install https://www.autohotkey.com/
  2. Copy and save the content of mac.ahk in a text file, named as mac.ahk
  3. Double click on mac.ahk file

Auto start after Windows startup

Complete the step of "To Run Once" section first.

Place mac.ahk file (or make a shortcut) at C:\Users\<USERNAME>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Docs:
; https://autohotkey.com/docs/Hotkeys.htm
; https://autohotkey.com/docs/KeyList.htm
; Ref https://autohotkey.com/board/topic/60675-osx-style-command-keys-in-windows/
; You need to disable "Between input languages" shotcut from Control Panel\Clock, Language, and Region\Language\Advanced settings > Change lanugage bar hot keys
; Universal shotcuts
$!x::Send ^x
$!c::Send ^c
$!v::Send ^v
$!s::Send ^s
$!a::Send ^a
$!z::Send ^z
$!+z::Send ^y
$!w::Send ^w
$!f::Send ^f
$!n::Send ^n
$!q::Send !{f4}
$!r::Send ^{f5}
$!m::Send {LWin Down}{Down}{LWin Up}
$!`::Send {Alt Down}{Shift Down}{Tab}{Shift Up}
; Quick Switch Tab shotcuts
$!1::Send ^1
$!2::Send ^2
$!3::Send ^3
$!4::Send ^4
$!5::Send ^5
$!6::Send ^6
$!7::Send ^7
$!8::Send ^8
$!9::Send ^9
$!0::Send ^0
; Chrome shotcuts
$!t::Send ^t
$!+t::Send ^+t
$!+]::Send {Ctrl Down}{Tab Down}{Tab Up}{Ctrl Up}
$!+[::Send {Ctrl Down}{Shift Down}{Tab Down}{Tab Up}{Shift Up}{Ctrl Up}
$!l::Send ^l
; input methods
; $+,::Send ^,
; $+.::Send ^.
; navigation, selection, delete a word/till end
$!Left::Send {Home}
$!Right::Send {End}
$!Up::Send {Lctrl down}{Home}{Lctrl up}
$!Down::Send {Lctrl down}{End}{Lctrl up}
$#Left::Send {ctrl down}{Left}{ctrl up}
$#Right::Send {ctrl down}{Right}{ctrl up}
$#+Left::Send {ctrl down}{shift down}{Left}{shift up}{ctrl up}
$#+Right::Send {ctrl down}{shift down}{Right}{shift up}{ctrl up}
$!+Left::Send {shift down}{Home}{shift up}
$!+Right::Send {shift down}{End}{shift up}
$!+Up::Send {Ctrl Down}{shift down}{Home}{shift up}{Ctrl Up}
$!+Down::Send {Ctrl Down}{shift down}{End}{shift up}{Ctrl Up}
!BS::Send {LShift down}{Home}{LShift Up}{Del}
#BS::Send {LCtrl down}{BS}{LCtrl up}
$#Space::Send {Ctrl Down}{LWin Down}{Space}{LWin Up}{Ctrl Up}
@Veronika-Kot
Copy link

Universal shotcuts started working for me only after I replaced $!x::Send ^x with $#x::Send ^x (replaced ! with #).
Haven't tried other shortcuts.

@profdorly
Copy link

Thank you so much! Works without any problem. :D

@edoardoc
Copy link

this is the closest I could get, thank you.

PS: I am running this with a pre-code to run the ahk in admin mode, I read that it sorts out some compatibility problems in win10, what do you think?

full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}

MsgBox A_IsAdmin: %A_IsAdmin%`nCommand line: %full_command_line%

@DannyDannyDanny
Copy link

Previously I would use the winkey to snap windows around on screen:

  • Win+
  • Win+
  • Win+
  • Win+

They no longer work - is there an easy workaround? 👍

@ascendbruce
Copy link
Author

Hi @DannyDannyDanny, I guess it might be conflicting with one of the Left/Right/Up/Down config group between line 58-71, but I don't have Windows PC with me right now. Could you try disabling those lines and re-run the script?

@DannyDannyDanny
Copy link

You are right! Deleting lines L58-end resolved the arrow-key issues. I can now snap windows and use arrows to change selection the the window navigator (win: alt-tab). There'll be some consequences of deleting those lines. So far I haven't figured out whats missing. Thanks @ascendbruce! 🥇

@Aghyads
Copy link

Aghyads commented Apr 17, 2021

#$! can you please explain what does each of these represent in. I want to make changes, but I'm not sure

@ascendbruce
Copy link
Author

ascendbruce commented Apr 19, 2021

Hi @Aghyads, you can find their meanings in AutoHotKey's official doc, under the "Keys and their mysterious symbols" section: https://www.autohotkey.com/docs/Tutorial.htm#s21

And for $, it's a Hotkey Modifier Symbols, you can find the usage here: https://www.autohotkey.com/docs/Hotkeys.htm#Symbols

@tornikenats
Copy link

For some reason #BS::Send {LCtrl down}{BS}{LCtrl up} doesn't work. I've tried different symbols for backspace like BackSpace and BACKSPACE but it doesn't work. It only deletes one character instead of a word.

@ascendbruce
Copy link
Author

Hi @tornikenats, maybe also try:

$#BS::Send {LCtrl down}{BS}{LCtrl up}

If that works, I will update the gist. But I don't have a windows machine with me right now.

@tornikenats
Copy link

Hi @ascendbruce, everything works, it was another one of the lines I added that broke it. Feel free to delete my comment to reduce noise.

@Aghyads
Copy link

Aghyads commented Apr 27, 2021

@ascendbruce, dear, do you know how I can create the move forward/ redo shortcut.
It is not working on Microsoft office programs.
here is my script:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

; Docs:
; https://autohotkey.com/docs/Hotkeys.htm
; https://autohotkey.com/docs/KeyList.htm
; Ref https://autohotkey.com/board/topic/60675-osx-style-command-keys-in-windows/

; You need to disable "Between input languages" shotcut from Control Panel\Clock, Language, and Region\Language\Advanced settings > Change lanugage bar hot keys

; Universal shotcuts
^q::!F4
#q::!F4

$!x::Send ^x
$!c::Send ^c
$!v::Send ^v
$!s::Send ^s
$!a::Send ^a
$!z::Send ^z
$!+z::Send ^y
$!w::Send ^w
$!f::Send ^f
$!n::Send ^n
$!q::Send !{f4}
$!r::Send ^{f5}
$!m::Send {LWin Down}{Down}{LWin Up}
$!`::Send {Alt Down}{Shift Down}{Tab}{Shift Up}

; Quick Switch Tab shotcuts

$!1::Send ^1
$!2::Send ^2
$!3::Send ^3
$!4::Send ^4
$!5::Send ^5
$!6::Send ^6
$!7::Send ^7
$!8::Send ^8
$!9::Send ^9
$!0::Send ^0

; Chrome shotcuts

$!t::Send ^t
$!+t::Send ^+t
$!+]::Send {Ctrl Down}{Tab Down}{Tab Up}{Ctrl Up}
$!+[::Send {Ctrl Down}{Shift Down}{Tab Down}{Tab Up}{Shift Up}{Ctrl Up}
$!l::Send ^l

; input methods

; $+,::Send ^,
; $+.::Send ^.

; navigation, selection, delete a word/till end

$!Left::Send {Home}
$!Right::Send {End}
$!Up::Send {Lctrl down}{Home}{Lctrl up}
$!Down::Send {Lctrl down}{End}{Lctrl up}

$#Left::Send {ctrl down}{Left}{ctrl up}
$#Right::Send {ctrl down}{Right}{ctrl up}
$#+Left::Send {ctrl down}{shift down}{Left}{shift up}{ctrl up}
$#+Right::Send {ctrl down}{shift down}{Right}{shift up}{ctrl up}

$!+Left::Send {shift down}{Home}{shift up}
$!+Right::Send {shift down}{End}{shift up}
$!+Up::Send {Ctrl Down}{shift down}{Home}{shift up}{Ctrl Up}
$!+Down::Send {Ctrl Down}{shift down}{End}{shift up}{Ctrl Up}

!BS::Send {LShift down}{Home}{LShift Up}{Del}
#BS::Send {LCtrl down}{BS}{LCtrl up}

$#Space::Send {Ctrl Down}{LWin Down}{Space}{LWin Up}{Ctrl Up}

^space:: Send ^{esc}

LControl & Tab::AltTab

; Google Search highlighted text
^+c::
{
Send, ^c
Sleep 50
Run, http://www.google.com/search?q=%clipboard%
Return
}

; Press ~ to move up a folder in Explorer
#IfWinActive, ahk_class CabinetWClass
`::Send !{Up}
#IfWinActive
return

; Empty trash
^del::FileRecycleEmpty ; win + del
return

Capslock::
Send {LWin down}{Space down}
KeyWait, LWin
Send {Space up}{Lwin up}
return

^h::WinMinimize, A ; Ctrl+Down
return

F13::
Send {F2}
return

^F19::
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
Return

#^1::¡
#^+1::/
#^2::€
#^+2::™
#^3::£
#^+3::‹
#^4::¢
#^+4::›
#^5::∞
#^6::§
#^+6::fl
#^7::¶
#^+7::‡
#^8::•
#^+8::°
return

Any suggestions to solve that?

Thanks!

@sgrayrw
Copy link

sgrayrw commented May 8, 2021

Thanks so much!

@samuelbalogh
Copy link

Amazing, thank you so much for this!

@LoneExile
Copy link

last line change language it space 1 char, how can I fixed it.

Thanks for script btw

@joaquim-oliveira-neto
Copy link

Hi @ascendbruce thank you very much for this, you really saved my life! I come from mac and in my new job we use Windows and I cannot stand Windows shortcuts, my mind just bug.

I need your help for other 4 things that I do on mac that i cannot do on Windows:
1 - On Chrome I usually press commad + tap on touchpad to open a link on a new tab. So how can I do alt + tap and send crt + tap?
2 - How can I drag windows with three fingers, as I do on Mac?
3 - On Mac I use command + ' to change windows of the same App (which is different from command + tab which change from app to app). Is there a similar way to do that on Windows?
4 - Last but not least: on Mac I use command + space to open the Spotlight. On Windows I use a three finger tap. Is there a way to use it as alt + space?

Could you help me my friend?

@aa-dit-yuh
Copy link

@joaquim-oliveira-neto

  1. Add this line to mac.ahk to mimic command+tap:
$!LButton::Send ^{LButton}
  1. Use PowerToys Run to mimic Spotlight: https://docs.microsoft.com/en-us/windows/powertoys/run

@joaquim-oliveira-neto
Copy link

@aditnryn Thank you very much!
2 - I think that is impossible
3 - I tried to use https://neosmart.net/EasySwitch/ but it didn't worked well.

@edoardoc
Copy link

edoardoc commented Mar 4, 2022

@aditnryn @joaquim-oliveira-neto
2 - it is indeed impossible :/ and there is an ongoing discussion about the reasons and some surrogates at https://superuser.com/questions/1303810/three-finger-drag-on-windows

@ifedyukin
Copy link

Thanks a lot!
Also internal windows screenshot tool mapping
+!4::Send {LWin Down}{Shift Down}{S}{Shift Up}{LWin Up}

@zcharef
Copy link

zcharef commented Aug 1, 2022

this doesn't work for me #July 2022

@stevenilsen123
Copy link

Trying to create a better solution for this here: https://github.com/stevenilsen123/mac-keyboard-behavior-in-windows
Feedback welcome!

@ascendbruce
Copy link
Author

@stevenilsen123 That is cool!!!

I rarely use Windows PC now. I would love to try it out next time when I get a chance!

@SnoWolfT
Copy link

Thanks a lot!

@giacorri
Copy link

Thanks!! I can finally learn only one set of shorcuts and forget stupid windows one!!

@nullptre
Copy link

nullptre commented Sep 7, 2024

I've updated it to AutoHotKey v2 and added CapsLock for language switching and fix to the app menu on Alt.

#Requires AutoHotkey v2.0
; #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
; SendMode Input  ; Recommended for new scripts due to its superior speed and reliability."
; SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Docs:
; https://autohotkey.com/docs/Hotkeys.htm
; https://autohotkey.com/docs/KeyList.htm
; Ref https://autohotkey.com/board/topic/60675-osx-style-command-keys-in-windows/

; You need to disable "Between input languages" shotcut from Control Panel\Clock, Language, and Region\Language\Advanced settings > Change lanugage bar hot keys

; Block single press on Alt so it doesn't trigger app menu
~Alt::Send "{Blind}{vkE8}"

; Universal shotcuts

$!x::Send "^x"
$!c::Send "^c"
$!s::Send "^s"
$!v::Send "^v"
$!a::Send "^a"
$!z::Send "^z"
$!+z::Send "^y"
$!w::Send "^w"
$!f::Send "^f"
$!n::Send "^n"
$!q::Send "!{f4}"
$!r::Send "^{f5}"
$!m::Send "{LWin Down}{Down}{LWin Up}"
$!`::Send "{Alt Down}{Shift Down}{Tab}{Shift Up}"

; Quick Switch Tab shotcuts

$!1::Send "^1"
$!2::Send "^2"
$!3::Send "^3"
$!4::Send "^4"
$!5::Send "^5"
$!6::Send "^6"
$!7::Send "^7"
$!8::Send "^8"
$!9::Send "^9"
$!0::Send "^0"

; Chrome shotcuts

$!t::Send "^t"
$!+t::Send "^+t"
$!+]::Send "{Ctrl Down}{Tab Down}{Tab Up}{Ctrl Up}"
$!+[::Send "{Ctrl Down}{Shift Down}{Tab Down}{Tab Up}{Shift Up}{Ctrl Up}"
$!l::Send "^l"

; input methods

$+,::Send "^,"
$+.::Send "^."

; Using CapsLock to switch languages, see https://superuser.com/questions/429930/using-capslock-to-switch-the-keyboard-language-layout-on-windows-7
; Uncomment the section below
; SetCapsLockState('AlwaysOff')
; +CapsLock::{
;     if (GetKeyState("CapsLock", "T")) {
;         SetCapsLockState('Off')
;     } else {
;         SetCapsLockState('On')
;     }
; }
; CapsLock::Send("{Shift down}{Alt down}{Shift up}{Alt up}")

; navigation, selection, delete a word/till end

#HotIf !WinActive("Task Switching") ; disable it when swtitching between windows
$!Left::Send "{Home}"
$!Right::Send "{End}"
$!Up::Send "{Lctrl down}{Home}{Lctrl up}"
$!Down::Send "{Lctrl down}{End}{Lctrl up}"
#HotIf

$#Left::Send "{ctrl down}{Left}{ctrl up}"
$#Right::Send "{ctrl down}{Right}{ctrl up}"
$#+Left::Send "{ctrl down}{shift down}{Left}{shift up}{ctrl up}"
$#+Right::Send "{ctrl down}{shift down}{Right}{shift up}{ctrl up}"

$!+Left::Send "{shift down}{Home}{shift up}"
$!+Right::Send "{shift down}{End}{shift up}"
$!+Up::Send "{Ctrl Down}{shift down}{Home}{shift up}{Ctrl Up}"
$!+Down::Send "{Ctrl Down}{shift down}{End}{shift up}{Ctrl Up}"

!BS::Send "{LShift down}{Home}{LShift Up}{Del}"
#BS::Send "{LCtrl down}{BS}{LCtrl up}"

$#Space::Send "{Ctrl Down}{LWin Down}{Space}{LWin Up}{Ctrl Up}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment