Skip to content

Instantly share code, notes, and snippets.

@jialeicui
Last active June 18, 2025 03:31
Show Gist options
  • Save jialeicui/0a6f5328beb83ec525fc3e620f4be0b4 to your computer and use it in GitHub Desktop.
Save jialeicui/0a6f5328beb83ec525fc3e620f4be0b4 to your computer and use it in GitHub Desktop.
; An AutoHotKey script mapping most common OSX keyboard shortcuts to Windows 10
; Useful if you're used to using Apple Keyboard and switch between OSX and W10
; - clipboard (CMD+C, CMD+V, CMD+X, CMD+ALT+SHIFT+V)
; - app-switching (CMD+Tab)
; - text editor cursor manipulation - CMD+Arrow, CMD+SHIFT+Arrow, ALT+Arrow, ALT+SHIFT+Arrow
; - window management - CMD+Q, CMD+`
; - in-browser tabs - CMD+T, CMD+SHIFT+T, CMD+W, CMD+1...CMD+9,
; - standard actions - CMD+N, CMD+SHIFT+N, CMD+O, CMD+SHIFT+O, CMD+P, CMD+S, CMD+SHIFT+S
; - undo/redo - CMD+Z, CMD+SHIFT+Z
; - spotlight search (CMD+Space)
; - task manager (CMD+ALT+ESC)
; - 1-password - CMD+\
; - magnet-like window snapping (CTRL+ALT+Arrow, CTRL+ALT+ENTER)
; - other
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
show_class()
{
bbb := WinActive("WeTERM")
MsgBox, "%bbb%"
WinGetClass, class, A
MsgBox, The active window's class is "%class%".
Clipboard = %class%
}
#i::show_class()
; =====================
; 1. clipboard
; - copy (CMD+C)
; - paste (CMD+V)
; - cut (CMD+X)
; - paste with dest formatting (CMD+ALT+SHIFT+V)
#c::Send ^c
#v::Send ^v
#x::Send ^x
#!+v::Send ^+v
; =====================
; 2. text editing - cursor manipulation
; - jump to beginning/end of line (CMD+Left/Right)
; - select to beginning/end of line (CMD+SHIFT+Arrow)
; - move between words (ALT+Arrow)
; - select by word (ALT+SHIFT+Arrow)
#Left::Send {Home}
#+Left::Send +{Home}
#Right::Send {End}
#+Right::Send +{End}
#Up::Send ^{Home}
#+Up::Send ^+{Home}
#Down::Send ^{End}
#+Down::Send ^+{End}
#Backspace::Send +{Home}{Delete}
!Backspace::Send ^{Backspace}
!Left::Send ^{Left}
!+Left::Send ^+{Left}
!Right::Send ^{Right}
!+Right::Send ^+{Right}
^g::Send {Home}
^+g::Send {End}
; =====================
; 2b. text editor
; - select all (CMD+A)
; - find (CMD+F)
; - formatting (CMD+B, CMD+I, CMD+U)
; - change font size (CMD+SHIFT+>, CMD+SHIFT+<)
#a::Send ^a
#f::Send ^f
#b::Send ^b
;#i::Send ^i
;#u::Send ^u
#+>::Send ^+>
#+<::Send ^+<
; =====================
; 3. window management
; - quit app (CMD+Q)
; - switch between
; - close window/ta (CMD+W), CMD+`
; disclaimer: CMD+` requires Easy Window Switcher neosmart (https://neosmart.net/Download)
#q::Send !{F4}
#`::Send !~
; =====================
; 4. In-browser actions
; - new tab (CMD+T)
; - reopen recently closed tab (CMD+SHIFT+T)
; - close tab (CMD+W)
; - zoom (CMD+=, CMD+SHIFT+=)
; - switch between tabs (CMD+1...CMD+0)
#t::Send ^t
#+t::Send ^+t
#w::Send ^w{Esc}
#=::Send ^=
#-::Send ^-
#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
; =====================
; 5. standard actions
; - new file (CMD+N)
; - new item, used in several apps - (CMD+SHIFT+N),
; - open file (CMD+O)
; - print (CMD+P)
; - save (CMD+S)
; - save-as (CMD+SHIFT+S)
; - undo (CMD+Z)
; - redo (CMD+SHIFT+Z)
#n::Send ^n
#+n::Send ^+n
#o::Send ^o
#+o::Send ^+o
#p::Send ^p
#+p::Send ^+p
#s::Send ^s
#+s::Send ^!s
; =====================
; 6. undo/redo (CMD+Z, CMD+SHIFT+Z)
#z::Send ^z
#+z::Send ^y
; =====================
; 7. additional in-app commands
; - CMD+R
; - CMD+D
; - CMD+\ (requires 1password)
; - CMD+], CMD+[, CMD+\ (Visual Studio Code)
#r::Send ^r
#d::Send ^d
#\::Send ^\
#]::Send ^]
#[::Send ^[
#/::Send ^/
; =====================
; 8. win10 capture screenshot CTRL+SHIFT+S (since CMD+SHIFT+S has been remapped to Save As)
^+s::Send #+s
; =====================
; 9. spotlight (CMD+SPACE), tasks (CMD+ALT+ESC)
#Space::Send ^{Space}
#!Esc::Send ^+{Esc}
; =====================
; 10. App-Switcher (CMD+Tab, CMD+Paragraph)
; unfortunately CMD+SHIFT+Tab doesn't work (AutoHotKey has very limited support for this, so we use CMD+Paragraph (the key above Tab) to switch to previous app)
<#Tab::AltTab
<#Sc056::ShiftAltTab
; =====================
; 11. MagnetApp-Like window snapping - CTRL+ALT+Arrow
^!Left::WinMove, A,, 0, 0, (A_ScreenWidth/2), (A_ScreenHeight)
^!Right::WinMove, A,, (A_ScreenWidth/2), 0, (A_ScreenWidth/2), (A_ScreenHeight)
^!Up::WinMove, A,, 0, 0, (A_ScreenWidth), (A_ScreenHeight/2)
^!Down::WinMove, A,, 0, (A_ScreenHeight/2), (A_ScreenWidth), (A_ScreenHeight/2)
^!u::WinMove, A,, 0, 0, (A_ScreenWidth/2), (A_ScreenHeight/2)
^!i::WinMove, A,, (A_ScreenWidth/2), 0, (A_ScreenWidth/2), (A_ScreenHeight/2)
^!j::WinMove, A,, 0, (A_ScreenHeight/2), (A_ScreenWidth/2), (A_ScreenHeight/2)
^!k::WinMove, A,, (A_ScreenWidth/2), (A_ScreenHeight/2), (A_ScreenWidth/2), (A_ScreenHeight/2)
; MagnetApp-Like maximize/restore window - CTRL+ALT+Enter
^!Enter::
SysGet, VirtualScreenWidth, 78
WinGetPos, X, Y, Width, Height, A
If (Virtualscreenwidth = A_ScreenWidth) {
If (Width < A_ScreenWidth) {
WinMaximize, A
} Else {
WinRestore, A
}
}
Return
global PreviousActiveWindow
#u::
DetectHiddenWindows, On
if (WinExist("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")) {
if(WinActive("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")) {
WinActivate, ahk_id %PreviousActiveWindow%
} else {
WinGet, PreviousActiveWindow, , A ; 'A' for currently active window
WinActivate, ahk_class CASCADIA_HOSTING_WINDOW_CLASS
}
} else {
TerminalLink = %localappdata%\Microsoft\WindowsApps\wt.exe
if FileExist(TerminalLink) {
WinGet, PreviousActiveWindow, , A ; 'A' for currently active window
Run, %TerminalLink%
} else {
MsgBox, Windows Terminal not installed
}
}
Return
; emacs keybinding without windows terminal
;#IfWinNotActive ahk_class CASCADIA_HOSTING_WINDOW_CLASS
#If not (WinActive("WeTERM") or WinActive("ahk_class CASCADIA_HOSTING_WINDOW_CLASS") or WinActive("ahk_class Chrome_WidgetWin_1"))
$^a::Send {Home}
^e::Send {End}
^n::Send {Down}
$^p::Send {Up}
^b::Send {Left}
^f::Send {Right}
^h::Send {Backspace}
^d::Send {Delete}
return
!F10::TOP()
!F11::RGW()
!F12::FWT()
TOP(){
WinGetTitle, activeWindow, A
Winset, Alwaysontop, , A
}
RGW(){
Loop, Reg, HKEY_CURRENT_USER\SOFTWARE\miHoYo, KVR
{
if (A_LoopRegName = "Screenmanager Is Fullscreen mode_h3981298716"){
RegWrite, 0
RegRead, value
MsgBox, %A_LoopRegName% = %value% (%A_LoopRegType%)
}
}
}
; FWT - Fullscreen window toggle
; https://autohotkey.com/boards/viewtopic.php?p=123166#p123166
FWT(hwnd:=""){
MsgBox, "aaa"
static MONITOR_DEFAULTTONEAREST := 0x00000002
static WS_CAPTION := 0x00C00000
static WS_SIZEBOX := 0x00040000
static WindowStyle := WS_CAPTION|WS_SIZEBOX
static A := []
if (!hwnd) ; If no window handle is supplied, use the window under the mouse
MouseGetPos,,, hwnd
Win := "ahk_id " hwnd ; Store WinTitle
WinGet, S, Style, % Win ; Get window style
if (S & WindowStyle) { ; If not borderless
A[Win, "Style"] := S & WindowStyle ; Store existing style
WinGet, IsMaxed, MinMax, % Win ; Get/store whether the window is maximized
if (A[Win, "Maxed"] := IsMaxed = 1 ? true : false)
WinRestore, % Win
WinGetPos, X, Y, W, H, % Win ; Store window size/location
A[Win, "X"] := X, A[Win, "Y"] := Y, A[Win, "W"] := W, A[Win, "H"] := H
WinSet, Style, % -WindowStyle, % Win ; Remove borders
hMon := DllCall("User32\MonitorFromWindow", "Ptr", hwnd, "UInt", MONITOR_DEFAULTTONEAREST)
VarSetCapacity(monInfo, 40), NumPut(40, monInfo, 0, "UInt")
DllCall("User32\GetMonitorInfo", "Ptr", hMon, "Ptr", &monInfo)
WinMove, % Win,, monLeft := NumGet(monInfo, 4, "Int") ; Move and resize window
, monTop := NumGet(monInfo, 8, "Int")
, (monRight := NumGet(monInfo, 12, "Int")) - monLeft
, (monBottom := NumGet(monInfo, 16, "Int")) - monTop
}
else if A[Win] { ; If borderless
WinSet, Style, % "+" A[Win].Style, % Win ; Reapply borders
WinMove, % Win,, A[Win].X, A[Win].Y, A[Win].W, A[Win].H ; Return to original position
if (A[Win].Maxed) ; Maximize if required
WinMaximize, % Win
A.Delete(Win)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment