congdantoancau

Capslock Windows Switcher [NEW]

Jul 13th, 2020
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; CAPSLOCK WINDOWS SWITCHER
  2.  
  3. ; Initial variables
  4. ; Can using just one variables (GLOBAL_WIN_STORED) for both of following two var instead
  5. ; but keep them separate will help to keep the code more clear
  6. WinStoreByKey :=
  7. WinStoreByMouse :=
  8.  
  9. h_taskbar := 40 ; height of the taskbar
  10. w_spacetotray := 200 ; width count from the middle of the taskbar to the system tray
  11.     ; value depend on if the system tray is full of program or not
  12.  
  13. ; Left mouse button store the window id and be used when the Capslock is trigger
  14. ~LButton::
  15.     CoordMode, Mouse, Screen
  16.     MouseGetPos, x, y
  17.     ; check if user clicked on the programs area on the taskbar
  18.     if (x > h_taskbar && x < A_ScreenWidth / 2 + w_spacetotray && y > A_ScreenHeight - h_taskbar) {
  19.         ; get and assign new win id as a lastwin
  20.         ; and when the hot key is burned so it will go to this {lastwin}
  21.        
  22.         lastwin := WinStoreByKey
  23.         WinGet, WinStoreByMouse, ID, a
  24.         WinStoreByKey := WinStoreByMouse
  25.  
  26.     }
  27. return
  28.  
  29. ; CapsLock switch to the last active window
  30. CapsLock:: 
  31.     if (lastwin) { ; the lastwin is exist in the memory
  32.  
  33.         ; Store new windows id and check it before switch to the lastwin
  34.         Winget, newwin, ID, a
  35.        
  36.         if (newwin == lastwin) { ; In the case last window was closed
  37.  
  38.             TrayTip, WinSwitcher, Last window is the same with this window.
  39.             ; switch to the last window by available Windows hotkey
  40.             send !{esc}
  41.         }
  42.         else { ; No problem with the new window id, so switch right away to the new win
  43.  
  44.             WinActivate, ahk_id %lastwin%
  45.  
  46.             ; assign the new win as a lastwin after switched window
  47.             lastwin := newwin
  48.             ; Get the new win id then send to mouse click action
  49.             Winget, WinStoreByKey, ID, a
  50.         }
  51.     } else { ; there are no last window in the memory (this will work at the first time when the Script is trigged)
  52.  
  53.         ; get the new window id
  54.         Winget, newwin, ID, a
  55.         send !{esc}
  56.  
  57.         ; assign the new window id as a lastwin after switch to the new win
  58.         lastwin := newwin
  59.     }
  60. return
Add Comment
Please, Sign In to add comment