Skip to content

Instantly share code, notes, and snippets.

@seperman
Last active June 24, 2020 06:22
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seperman/8064659 to your computer and use it in GitHub Desktop.
Save seperman/8064659 to your computer and use it in GitHub Desktop.
Auto Hot Key configs to make Windows shortcuts/keyboard like Mac
; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a
; semicolon, such as this one, are comments. They are not executed.
; This script has a special filename and path because it is automatically
; launched when you run the program directly. Also, any text file whose
; name ends in .ahk is associated with the program, which means that it
; can be launched simply by double-clicking it. You can have as many .ahk
; files as you want, located in any folder. You can also run more than
; one .ahk file simultaneously and each will get its own tray icon.
; SAMPLE HOTKEYS: Below are two sample hotkeys. The first is Win+Z and it
; launches a web site in the default browser. The second is Control+Alt+N
; and it launches a new Notepad window (or activates an existing one). To
; try out these hotkeys, run AutoHotkey again, which will load this file.
;#z::Run www.autohotkey.com
^!n::
IfWinExist Untitled - Notepad
WinActivate
else
Run Notepad
return
;LWin & x::Send ^x ;cut
;LWin & c::Send ^c ;copy
;LWin & v::Send ^v ;paste
;LWin & a::send ^a ;select all
;LWin & z::send ^z ;undo
;LWin & y::send ^y ;redo
;LWin & s::send ^s ;redo
;LWin & f::send ^f ;find
;LWin & d::send ^d
;LWin & g::send ^g
;LWin & k::send ^k
;LWin & l::send ^l
;LWin & Tab::AltTab
;Lwin::send {Alt}
!x::Send ^x ;cut
!c::Send ^c ;copy
!b::Send ^b ;copy
!v::Send ^v ;paste
!a::send ^a ;select all
!z::send ^z ;undo
!y::send ^y ;redo
!s::send ^s ;redo
!f::send ^f ;find
!k::send ^k
!d::send ^d
CapsLock::send {ctrl} ; CapsLock
PgUp:: return ; Page up
PgDn:: return ; page down
Volume_Up:: send {Alt Down}{PrintScreen}{Alt Up}
Volume_down:: send {Insert}
#`:: ; Next window
WinGetClass, ActiveClass, A
WinSet, Bottom,, A
WinActivate, ahk_class %ActiveClass%
return
#^`:: ; Last window
WinGetClass, ActiveClass, A
WinActivateBottom, ahk_class %ActiveClass%
return
!`:: ; Next window
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
IF WinClassCount = 1
Return
Else
WinGet, List, List, % "ahk_class " ActiveClass
Loop, % List
{
index := List - A_Index + 1
WinGet, State, MinMax, % "ahk_id " List%index%
if (State <> -1)
{
WinID := List%index%
break
}
}
WinActivate, % "ahk_id " WinID
return
!^`:: ; Last window
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
IF WinClassCount = 1
Return
Else
WinGet, List, List, % "ahk_class " ActiveClass
Loop, % List
{
index := List - A_Index + 1
WinGet, State, MinMax, % "ahk_id " List%index%
if (State <> -1)
{
WinID := List%index%
break
}
}
WinActivate, % "ahk_id " WinID
return
;----------------- Alt + tab ------------------------------
; Note: From now on whenever you run AutoHotkey directly, this script
; will be loaded. So feel free to customize it to suit your needs.
; Please read the QUICK-START TUTORIAL near the top of the help file.
; It explains how to perform common automation tasks such as sending
; keystrokes and mouse clicks. It also explains more about hotkeys.
@Yukaii
Copy link

Yukaii commented Jul 21, 2017

Thanks for sharing this script! I just found that the ahk_class wouldn't distinct electron applications(e.g., VSCode and Atom) from chromium base browser(Google Chrome and Opera). So I use ahk_exe instead and it works well! 😄

+ WinGet, ActiveProcess, ProcessName, A
+ WinGet, WinClassCount, Count, ahk_exe %ActiveProcess%
- WinGetClass, ActiveClass, A
- WinGet, WinClassCount, Count, ahk_class %ActiveClass%

  IF WinClassCount = 1
      Return
  Else
+ WinGet, List, List, % "ahk_exe " ActiveProcess
- WinGet, List, List, % "ahk_class " ActiveClass
  Loop, % List
  {
      index := List - A_Index + 1
      WinGet, State, MinMax, % "ahk_id " List%index%
      if (State <> -1)
      {
          WinID := List%index%
          break
      }
  }
  WinActivate, % "ahk_id " WinID
  return

@xgdgsc
Copy link

xgdgsc commented Jan 31, 2018

@Yukaii Thanks. That works well. Is it possible to switch only on current desktop?

@elisemaki
Copy link

elisemaki commented Nov 12, 2018

@seperman, this is great. Thank you very much.

I still have problems with

!`:: ; Next window

as it seems to be identical with

!^`:: ; Last window

I would like to toggle the windows so that the most recent windows are activated first like in

#`:: ; Next window

, but without needing to send the topmost windows to the bottom. When one has more than one monitor, it is optimal that you can see the contents of inactive windows.

Unfortunately, I have been unable to edit the code of

!`:: ; Next window

window to suit my needs. I wonder if someone could help out?


Here is my hunch how to think about this, correct me if I am wrong.
I tried to edit your code and figured out that in order to reverse the "!:: ; Next window", we should start with changing index := List - A_Index + 1to index:=A_Indexin!^:: ; Last window
, and take it from there.

If, for instance List=4, then
1 should be 4
2 should be 3
3 should be 2
4 should be 1

We see that you can reverse the scale by simply having the A_Index as the new value.
List- A_Index +1 = Old value
=> New Value = A_Index

@sopepos
Copy link

sopepos commented Feb 22, 2019

index := List - A_Index + 1 in "last window" should be

    index := A_Index + 1
    if index > List
        index := 1

@JuanmaMenendez
Copy link

Nice script!

I created one similar to switch between open Windows but with some small improvements like it works besides regular Window Apps with Chrome Shortcuts and Chrome Apps.

https://github.com/JuanmaMenendez/AutoHotkey-script-Open-Show-Apps/blob/master/AutoHotkey-script-Switch-Windows-same-App.ahk

Also, I have another script that could work well in tandem with this one because you will be able to Open, Restore or Minimize (if it is already opened) the desired Apps, using the shortcuts key (hotkeys) that you want to set. Examples:

F7:: OpenOrShowAppBasedOnExeName("C:\Windows\System32\SnippingTool.exe")

F8:: OpenOrShowAppBasedOnWindowTitle("Gmail", "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --app=https://mail.google.com/mail/")

Feel free to check my repo and give me your thoughts ;)

https://github.com/JuanmaMenendez/AutoHotkey-script-Open-Show-Apps

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