Skip to content

Instantly share code, notes, and snippets.

@lxe
Created July 11, 2024 17:18
Show Gist options
  • Save lxe/56db4493c87d2da51cce6217de0f0031 to your computer and use it in GitHub Desktop.
Save lxe/56db4493c87d2da51cce6217de0f0031 to your computer and use it in GitHub Desktop.
Make Windows be like Mac
#NoEnv ; Disables the automatic inclusion of certain predefined variables and functions.
SendMode Input ; Sets the SendMode to Input, which allows for more reliable sending of keystrokes.
SetWorkingDir %A_ScriptDir% ; Sets the working directory to the directory containing the script.
; Function to map Windows key combined with another key to the corresponding Ctrl key combination.
; If Shift key is not pressed, it sends Ctrl+key combination.
; If Shift key is pressed, it sends Win+key combination using the {Blind} option to prevent triggering the Windows key menu.
MapWinToCtrl(key) {
if (!GetKeyState("Shift", "P")) {
Send ^%key%
} else {
Send {Blind}#%key%
}
}
; Enable the use of the keyboard hook for hotkeys.
#UseHook On
LWin & w::MapWinToCtrl("w") ; Close
LWin & c::MapWinToCtrl("c") ; Copy
LWin & v::MapWinToCtrl("v") ; Paste
LWin & s::MapWinToCtrl("s") ; Save
LWin & a::MapWinToCtrl("a") ; Select All
LWin & z::MapWinToCtrl("z") ; Undo
LWin & y::MapWinToCtrl("y") ; Redo
LWin & /::MapWinToCtrl("/") ; Comment/Uncomment
LWin & i::MapWinToCtrl("i") ; Copilot
; Allow normal functioning of the Windows key
LWin::Send {LWin}
; Switch between windows of the same type
#`::
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
if (WinClassCount = 1)
return
WinGet, WindowList, List, ahk_class %ActiveClass%
Loop, %WindowList%
{
index := WindowList - A_Index + 1
WinGet, State, MinMax, % "ahk_id " WindowList%index%
if (State <> -1)
{
WinActivate, % "ahk_id " WindowList%index%
break
}
}
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment