From The Compiler, 6 Years ago, written in Autohotkey.
Embed
  1. ;;;;;;;;;;;
  2. ;;; Init ;;
  3. ;;;;;;;;;;;
  4.  
  5. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  6. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  7. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  8.  
  9. SetBatchLines, -1         ; maximize script speed!
  10. OnExit, CleanUp           ;clean up in case of error (otherwise some windows will get lost)
  11.  
  12. numDesktops := 9          ; maximum number of desktops
  13. curDesktop := 1           ; index number of current desktop
  14. lock = 0                  ; lock to prevent running both hotkeys at same time
  15.  
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;
  17. ;; Focus follows mouse ;;
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;
  19.  
  20. DllCall("SystemParametersInfo",UInt,0x1001,UInt,0,UInt,1,UInt,1 | 2)
  21.  
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;;; US Keyboard layout ;;
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;
  25.  
  26. {
  27.   {
  28.         en := DllCall("LoadKeyboardLayout", "Str", "00000409", "Int", 1)
  29.         PostMessage 0x50, 0, %en%,, A
  30.   }
  31. }
  32.  
  33.  
  34. ;;;;;;;;;;;;;;;;;;;;;;
  35. ;;; Remap Capslock ;;;
  36. ;;;;;;;;;;;;;;;;;;;;;;
  37.  
  38. Capslock::Esc
  39. Break::Capslock
  40.  
  41. ;;;;;;;;;;;;;;;;;;;;;
  42. ;;; Window tiling ;;;
  43. ;;;;;;;;;;;;;;;;;;;;;
  44.  
  45. #down::WinMinimize,A
  46. #up::
  47.   SysGet, Scr, MonitorWorkArea
  48.   WinMove,A,,ScrLeft,ScrTop,ScrRight,ScrBottom
  49. return
  50. #left::
  51.   SysGet, Scr, MonitorWorkArea
  52.   WinMove,A,,ScrLeft,ScrTop,ScrRight/2,ScrBottom
  53. return
  54. #right::
  55.   SysGet, Scr, MonitorWorkArea
  56.   WinMove,A,,ScrRight/2,ScrTop,ScrRight,ScrBottom
  57. return
  58.  
  59. ;;;;;;;;;;;;;;;;;;;;;;
  60. ;;; Copy on select ;;;
  61. ;;;;;;;;;;;;;;;;;;;;;;
  62.  
  63. ~lButton::
  64.   MouseGetPos, cos_mousedrag_x, cos_mousedrag_y
  65.   keywait lbutton
  66.   mousegetpos, cos_mousedrag_x2, cos_mousedrag_y2
  67.   if (abs(cos_mousedrag_x2 - cos_mousedrag_x) > 20
  68.     or abs(cos_mousedrag_y2 - cos_mousedrag_y) > 20)
  69.   {
  70.     sendinput ^c
  71.   }
  72.   return
  73.  
  74. mbutton::
  75.   SendInput ^v
  76.   return
  77.  
  78.  
  79. ;;;;;;;;;;;;;;;
  80. ;;; Compose ;;;
  81. ;;;;;;;;;;;;;;;
  82.  
  83. AppsKey::                            
  84.   Input, composekeys, "BL2"
  85.   if composekeys = "u
  86.  {
  87.     Send ü
  88.  }
  89.  if composekeys = "a
  90.   {
  91.      Send ä
  92.   }
  93.   if composekeys = "o
  94.  {
  95.     Send ö
  96.  }
  97.  if composekeys = ,c
  98.  {
  99.     Send ç
  100.  }
  101.  if composekeys = os
  102.  {
  103.     Send §
  104.  }
  105.  if composekeys = ss
  106.  {
  107.     Send ß
  108.  }
  109.  if composekeys = e=
  110.  {
  111.     Send €
  112.  }
  113.  if composekeys = oo
  114.  {
  115.     Send °
  116.  }
  117.  if composekeys = ``a
  118.  {
  119.     Send à
  120.  }
  121.  if composekeys = 'e
  122.  {
  123.     Send é
  124.  }
  125.  if composekeys = ``e
  126.  {
  127.     Send è
  128.  }
  129. return
  130.  
  131. ;;;;;;;;;;;;;;;;
  132. ;;; Desktops ;;;
  133. ;;;;;;;;;;;;;;;;
  134.  
  135. #1::
  136.   if(lock = 0)
  137.   {
  138.      lock = 1
  139.      SwitchToDesktop(1)
  140.   }
  141. return
  142.  
  143. #2::
  144.   if(lock = 0)
  145.   {
  146.      lock = 1
  147.      SwitchToDesktop(2)      
  148.   }
  149. return
  150.  
  151. #3::
  152.   if(lock = 0)
  153.   {
  154.      lock = 1
  155.      SwitchToDesktop(3)      
  156.   }
  157. return
  158.  
  159. #4::
  160.   if(lock = 0)
  161.   {
  162.      lock = 1
  163.      SwitchToDesktop(4)      
  164.   }
  165. return
  166.  
  167. #5::
  168.   if(lock = 0)
  169.   {
  170.      lock = 1
  171.      SwitchToDesktop(5)
  172.   }
  173. return
  174.  
  175. #6::
  176.   if(lock = 0)
  177.   {
  178.      lock = 1
  179.      SwitchToDesktop(6)      
  180.   }
  181. return
  182.  
  183. #7::
  184.   if(lock = 0)
  185.   {
  186.      lock = 1
  187.      SwitchToDesktop(7)      
  188.   }
  189. return
  190.  
  191. #8::
  192.   if(lock = 0)
  193.   {
  194.      lock = 1
  195.      SwitchToDesktop(8)      
  196.   }
  197. return
  198.  
  199. #9::
  200.   if(lock = 0)
  201.   {
  202.      lock = 1
  203.      SwitchToDesktop(9)
  204.   }
  205. return
  206.  
  207. +#1::
  208.   if(lock = 0)
  209.   {
  210.      lock = 1
  211.      SendActiveToDesktop(1)      
  212.   }
  213. return
  214.  
  215. +#2::
  216.   if(lock = 0)
  217.   {
  218.      lock = 1
  219.      SendActiveToDesktop(2)
  220.   }
  221. return
  222.  
  223. +#3::
  224.   if(lock = 0)
  225.   {
  226.      lock = 1
  227.      SendActiveToDesktop(3)
  228.   }
  229. return
  230.  
  231. +#4::
  232.   if(lock = 0)
  233.   {
  234.      lock = 1
  235.      SendActiveToDesktop(4)            
  236.   }
  237. return
  238.  
  239. +#5::
  240.   if(lock = 0)
  241.   {
  242.      lock = 1
  243.      SendActiveToDesktop(5)      
  244.   }
  245. return
  246.  
  247. +#6::
  248.   if(lock = 0)
  249.   {
  250.      lock = 1
  251.      SendActiveToDesktop(6)
  252.   }
  253. return
  254.  
  255. +#7::
  256.   if(lock = 0)
  257.   {
  258.      lock = 1
  259.      SendActiveToDesktop(7)
  260.   }
  261. return
  262.  
  263. +#8::
  264.   if(lock = 0)
  265.   {
  266.      lock = 1
  267.      SendActiveToDesktop(8)            
  268.   }
  269. return
  270.  
  271. +#9::
  272.   if(lock = 0)
  273.   {
  274.      lock = 1
  275.      SendActiveToDesktop(9)      
  276.   }
  277. return
  278.  
  279. ; switch to the desktop with the given index number
  280. SwitchToDesktop(newDesktop)
  281. {
  282.   global
  283.  
  284.   WinGetActiveTitle, curWin    
  285.  
  286.   ; Removes the chance of getting Start Menu Shadow Frozen on Screen
  287.   if(curWin = "")
  288.      WinActivate, Program Manager
  289.      
  290.   ; Removes the chance of getting Tray or Tooltip shadows frozen on screen
  291.   ToolTip
  292.   TrayTip
  293.   WinClose, ahk_class SysShadow
  294.        
  295.   if (curDesktop <> newDesktop)
  296.   {
  297.      GetCurrentWindows(curDesktop)
  298.      ShowHideWindows(curDesktop, false)
  299.      ShowHideWindows(newDesktop, true)
  300.      activate_window := % active_id%newDesktop%
  301.      WinActivate, ahk_id %activate_window%
  302.      curDesktop := newDesktop
  303.   }
  304.  
  305.   lock = 0
  306.   return
  307. }
  308.  
  309. ; sends the given window from the current desktop to the given desktop
  310. SendToDesktop(windowID, newDesktop)
  311. {
  312.   global
  313.   if (curDesktop <> newDesktop)
  314.   {
  315.   RemoveWindowID(curDesktop, windowID)
  316.  
  317.   ; add window to destination desktop
  318.   windows%newDesktop% += 1
  319.   i := windows%newDesktop%
  320.  
  321.   windows%newDesktop%%i% := windowID
  322.    
  323.   WinHide, ahk_id %windowID%
  324.   Send, {ALT DOWN}{TAB}{ALT UP}   ; activate the right window
  325.   }
  326. }
  327.  
  328. ; sends the currently active window to the given desktop
  329. SendActiveToDesktop(newDesktop)
  330. {
  331.  
  332.   global
  333.  
  334.   WinGet, id, ID, A
  335.    
  336.   WinGetActiveTitle, curWin    
  337.    
  338. ;  sleep, 20            
  339.    
  340.   ; If Window Does not have a title, do not send it
  341.   if( (curWin = "") || (curWin = "Program Manager"))
  342.   {
  343.      lock = 0
  344. ;     sleep, 100
  345.      return      
  346.   }
  347.    
  348.   SendToDesktop(id, newDesktop)
  349. ;  sleep, 100
  350.   lock = 0
  351. }
  352.  
  353. ; removes the given window id from the desktop <desktopIdx>
  354. RemoveWindowID(desktopIdx, ID)
  355. {
  356.   global    
  357.   Loop, % windows%desktopIdx%
  358.   {
  359.      if (windows%desktopIdx%%A_Index% = ID)
  360.      {
  361.         windows%desktopIdx%%A_Index%=      ;Emiel: just empty the array element, array will be emptied by next switch anyway
  362.         Break
  363.      }
  364.   }
  365. }
  366.  
  367. ; this builds a list of all currently visible windows in stores it in desktop <index>
  368. GetCurrentWindows(index)
  369. {
  370.   global
  371.   WinGet, active_id%index%, ID, A                      ; get the current active window
  372.   emptyString =
  373.   StringSplit, windows%index%, emptyString             ; delete the entire windows_index_ array
  374.   WinGet, windows%index%, List,,, Program Manager      ; get list of all visible windows
  375.  
  376.   ; remove windows which we want to see on all virtual desktops
  377.   Loop, % windows%index%
  378.   {
  379.      id := % windows%index%%A_Index%
  380.      WinGetClass, windowClass, ahk_id %id%
  381.      if windowClass = Shell_TrayWnd     ; remove task bar window id
  382.           windows%index%%A_Index%=      ; just empty the array element, array will be emptied by next switch anyway
  383.      if windowClass = #32770            ; we also want multimontaskbar on all virtual desktops
  384.           windows%index%%A_Index%=      ; just empty the array element, array will be emptied by next switch anyway
  385.      if windowClass = cygwin/x X rl-xosview-XOsview-0   ; xosviews e.d.
  386.           windows%index%%A_Index%=      
  387.      if windowClass = cygwin/x X rl-xosview-XOsview-1   ; xosviews e.d.
  388.           windows%index%%A_Index%=      
  389.      if windowClass = MozillaUIWindowClass              ; Mozilla thunderbird
  390.      {
  391.        WinGet, ExStyle, ExStyle, ahk_id %id%
  392.          if (ExStyle & 0x8)  ; 0x8 is WS_EX_TOPMOST.
  393.           windows%index%%A_Index%=      
  394.      }
  395.      if alwaysShow%id% = 1
  396.           windows%index%%A_Index%=
  397.   }
  398. }
  399.  
  400. ; if show=true then shows windows of desktop %index%, otherwise hides them
  401. ShowHideWindows(index, show)
  402. {
  403.   global
  404.  
  405.   Loop, % windows%index%
  406.   {
  407.      id := % windows%index%%A_Index%
  408.      if show
  409.         WinShow, ahk_id %id%
  410.      else
  411.         WinHide, ahk_id %id%
  412.   }
  413. }
  414.  
  415.  
  416. ;;;;;;;;;;;
  417. ; Cleanup ;
  418. ;;;;;;;;;;;
  419.  
  420. CleanUp:
  421.         ; show all windows from all desktops on exit
  422.         Loop, %numDesktops%
  423.                 ShowHideWindows(A_Index, true)
  424.         ; Unset focus follows mouse
  425.         DllCall("SystemParametersInfo",UInt,0x1001,UInt,0,UInt,0,UInt,1 | 2)
  426.         ExitApp
  427.