Skip to content

Instantly share code, notes, and snippets.

@qxj
Forked from ascendbruce/README.md
Last active January 27, 2023 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qxj/b7dd4f1aa29975d450007b82ffd3e5b3 to your computer and use it in GitHub Desktop.
Save qxj/b7dd4f1aa29975d450007b82ffd3e5b3 to your computer and use it in GitHub Desktop.
Use mac style keyboard shortcuts on Windows with AutoHotkey (ahk) script

Use (most) macOS style keyboard shortcuts on Windows

Make Windows PC's shortcut act like macOS (Mac OS X)

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

Note that:

  1. you shouldn't change the modifier keys mapping with keyboard DIP. This script assumes you use a standard PC keyboard layout, and wish to use shortcuts as if it was a mac keyboard layout.
  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.

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
... ... ...

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

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 ; copy
$#v::Send ^v ; paste
$#+v::Send ^+v ; paste text
$#s::Send ^s ; save
$#a::Send ^a ; select all
$#z::Send ^z ; undo
$#+z::Send ^y ; redo
$#w::Send ^w ; close window
$#n::Send ^n ; new window
$#f::Send ^f ; find
$#q::Send !{f4} ; close window
$#r::Send ^{f5} ; refresh window
$#m::Send {LWin Down}{Down}{LWin Up} ; minimize window
$#^4::Send ^{PrintScreen} ; rectangle screen capture (FSCapture)
$#^l::DllCall("PowrProf\SetSuspendState", "Int", 0, "Int", 0, "Int", 0) ; hibernate or suspend
;;; Quick Switch Tab shotcuts
LWin & Tab::AltTab
$#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
SetTitleMatchMode, 2
#IfWinActive, ahk_exe chrome.exe
$#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
$^#z::Send ^+z ; switch last opened tab
#IfWinActive
;;; input methods
; $+,::Send ^,
; $+.::Send ^.
SetCapsLockState, AlwaysOff
+CapsLock::CapsLock
;CapsLock::Send ^{space} ; Swith input methods as macOS
CapsLock::Send {LShift down}{LShift Up}
;;; 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}
;;; Emacs keybinds
$#BS::Send {LShift down}{Home}{LShift Up}{Del}
$!BS::Send {LCtrl down}{BS}{LCtrl up} ; delete word backword
$^a::Send {Home} ; move to beginning of line
$^b::Send {Left} ; backward char
$^d::Send {Del} ; delete char forward
$^e::Send {End} ; move to end of line
$^f::Send {Right} ; forward char
$^k::Send {LShift down}{End}{LShift up}{Del} ; delete to end of line
$^n::Send {Down}
$^p::Send {Up}
$^w::Send {LCtrl down}{BS}{LCtrl up} ; delete word backword
$!b::Send {Alt down}{Left}{Alt up} ; backward word
$!d::Send {LCtrl down}{Del}{LCtrl up} ; delete word forward
$!f::Send {Alt down}{Right}{Alt up} ; forward word
LWin & F12::
EmacsKey :=! EmacsKey
Hotkey, ^a, Toggle
Hotkey, ^b, Toggle
Hotkey, ^d, Toggle
Hotkey, ^e, Toggle
Hotkey, ^f, Toggle
Hotkey, ^k, Toggle
Hotkey, ^n, Toggle
Hotkey, ^p, Toggle
Hotkey, ^w, Toggle
Hotkey, !b, Toggle
Hotkey, !d, Toggle
Hotkey, !f, Toggle
If EmacsKey
MsgBox, Emacs Keybind Disabled!
Else
MsgBox, Emacs Keybind Enabled!
Return
@stevenilsen123
Copy link

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

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