summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-07-20 12:03:49 +0200
committerFlorian Bruhin <me@the-compiler.org>2012-07-20 12:03:49 +0200
commit37984c14f35a82e4c4f6fafb82bcb82e735f7ea7 (patch)
treed91a127d9766a7c6a52d3e82dea3002ec99fad92
downloadwinunsuck-37984c14f35a82e4c4f6fafb82bcb82e735f7ea7.tar.gz
winunsuck-37984c14f35a82e4c4f6fafb82bcb82e735f7ea7.zip
Initial commit
-rw-r--r--winunsuck.ahk497
1 files changed, 497 insertions, 0 deletions
diff --git a/winunsuck.ahk b/winunsuck.ahk
new file mode 100644
index 0000000..0696b8f
--- /dev/null
+++ b/winunsuck.ahk
@@ -0,0 +1,497 @@
+;;;;;;;;;;;
+;;; Init ;;
+;;;;;;;;;;;
+
+; Avoids checking empty variables to see if they are environment variables (recommended for all new scripts).
+#NoEnv
+; Use SendInput instead of Send
+SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
+; Change PWD to the dir the script is in
+;SetWorkingDir %A_ScriptDir%
+; Skips the gentle method of activating a window and goes straight to the forceful method.
+#WinActivateForce
+; Don't display a tray icon
+; #NoTrayIcon
+
+SetBatchLines, 10ms ; maximize script speed!
+SetWinDelay, 0
+OnExit, CleanUp ;clean up in case of error (otherwise some windows will get lost)
+
+numDesktops := 9 ; maximum number of desktops
+curDesktop := 1 ; index number of current desktop
+lock = 0 ; lock to prevent running both hotkeys at same time
+
+;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Focus follows mouse ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;
+
+; DllCall("SystemParametersInfo",UInt,0x1001,UInt,0,UInt,1,UInt,1 | 2)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; US Keyboard layout ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;
+
+Loop
+{
+ #IfWinActive
+ {
+ en := DllCall("LoadKeyboardLayout", "Str", "00000409", "Int", 1)
+ PostMessage 0x50, 0, %en%,, A
+ }
+}
+
+
+;;;;;;;;;;;;;;;;;;;;;;
+;;; Remap Capslock ;;;
+;;;;;;;;;;;;;;;;;;;;;;
+
+Capslock::Esc
+Break::Capslock
+
+;;;;;;;;;;;;;;;;;;;;;
+;;; Window tiling ;;;
+;;;;;;;;;;;;;;;;;;;;;
+
+#down::WinMinimize,A
+#up::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrLeft,ScrTop,ScrRight,ScrBottom
+return
+#left::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrLeft,ScrTop,ScrRight/2,ScrBottom
+return
+#right::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrRight/2,ScrTop,ScrRight,ScrBottom
+return
+#Numpad0::WinMinimize,A
+#Numpad1::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrLeft,ScrBottom/2,ScrRight/2,ScrBottom/2
+return
+#Numpad2::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrLeft,ScrBottom/2,ScrRight,ScrBottom/2
+return
+#Numpad3::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrRight/2,ScrBottom/2,ScrRight/2,ScrBottom/2
+return
+#Numpad4::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrLeft,ScrTop,ScrRight/2,ScrBottom
+return
+#Numpad5::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrLeft,ScrTop,ScrRight,ScrBottom
+return
+#Numpad6::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrRight/2,ScrTop,ScrRight,ScrBottom
+return
+#Numpad7::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrLeft,ScrTop,ScrRight/2,ScrBottom/2
+return
+#Numpad8::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrLeft,ScrTop,ScrRight,ScrBottom/2
+return
+#Numpad9::
+ SysGet, Scr, MonitorWorkArea
+ WinMove,A,,ScrRight/2,ScrTop,ScrRight/2,ScrBottom/2
+return
+
+;;;;;;;;;;;;;;;;;;;;;;
+;;; Copy on select ;;;
+;;;;;;;;;;;;;;;;;;;;;;
+
+~lButton::
+ MouseGetPos, cos_mousedrag_x, cos_mousedrag_y
+ keywait lbutton
+ mousegetpos, cos_mousedrag_x2, cos_mousedrag_y2
+ if (abs(cos_mousedrag_x2 - cos_mousedrag_x) > 20
+ or abs(cos_mousedrag_y2 - cos_mousedrag_y) > 20)
+ {
+ if (!WinActive("ahk_class KiTTY"))
+ and (!WinActive("ahk_class Console_2_Main"))
+ and (!WinActive("ahk_class mintty"))
+ and (!WinActive("ahk_class rxvt00000298"))
+ and (!WinActive("ahk_class ConsoleWindowClass"))
+ and (!WinActive("ahk_class VNCviewer"))
+ and (!WinActive("ahk_class PuTTY"))
+ {
+ oldclipboard := ClipboardAll
+ Clipboard =
+ sendinput ^c
+ ClipWait
+ primarysel := Clipboard
+ Clipboard := oldclipboard
+ VarSetCapacity(oldclipboard, 0)
+ }
+ }
+ return
+
+mButton::
+ oldclipboard_2 := ClipboardAll
+ Clipboard := primarysel
+ Send ^v
+ Sleep 100
+ Clipboard := oldclipboard_2
+ VarSetCapacity(oldclipboard_2, 0)
+ return
+
+;;;;;;;;;;;;;;;
+;;; Compose ;;;
+;;;;;;;;;;;;;;;
+
+AppsKey::
+ Input, composekeys, "BL2"
+ if composekeys = "u
+ {
+ Send
+ }
+ if composekeys = "a
+ {
+ Send
+ }
+ if composekeys = "o
+ {
+ Send
+ }
+ if composekeys = ,c
+ {
+ Send
+ }
+ if composekeys = os
+ {
+ Send
+ }
+ if composekeys = ss
+ {
+ Send
+ }
+ if composekeys = e=
+ {
+ Send
+ }
+ if composekeys = oo
+ {
+ Send
+ }
+ if composekeys = ``a
+ {
+ Send
+ }
+ if composekeys = 'e
+ {
+ Send
+ }
+ if composekeys = ``e
+ {
+ Send
+ }
+return
+
+;;;;;;;;;;;;;;;;
+;;; Desktops ;;;
+;;;;;;;;;;;;;;;;
+
+#1::
+ if(lock = 0)
+ {
+ lock = 1
+ SwitchToDesktop(1)
+ }
+return
+
+#2::
+ if(lock = 0)
+ {
+ lock = 1
+ SwitchToDesktop(2)
+ }
+return
+
+#3::
+ if(lock = 0)
+ {
+ lock = 1
+ SwitchToDesktop(3)
+ }
+return
+
+#4::
+ if(lock = 0)
+ {
+ lock = 1
+ SwitchToDesktop(4)
+ }
+return
+
+#5::
+ if(lock = 0)
+ {
+ lock = 1
+ SwitchToDesktop(5)
+ }
+return
+
+#6::
+ if(lock = 0)
+ {
+ lock = 1
+ SwitchToDesktop(6)
+ }
+return
+
+#7::
+ if(lock = 0)
+ {
+ lock = 1
+ SwitchToDesktop(7)
+ }
+return
+
+#8::
+ if(lock = 0)
+ {
+ lock = 1
+ SwitchToDesktop(8)
+ }
+return
+
+#9::
+ if(lock = 0)
+ {
+ lock = 1
+ SwitchToDesktop(9)
+ }
+return
+
++#1::
+ if(lock = 0)
+ {
+ lock = 1
+ SendActiveToDesktop(1)
+ }
+return
+
++#2::
+ if(lock = 0)
+ {
+ lock = 1
+ SendActiveToDesktop(2)
+ }
+return
+
++#3::
+ if(lock = 0)
+ {
+ lock = 1
+ SendActiveToDesktop(3)
+ }
+return
+
++#4::
+ if(lock = 0)
+ {
+ lock = 1
+ SendActiveToDesktop(4)
+ }
+return
+
++#5::
+ if(lock = 0)
+ {
+ lock = 1
+ SendActiveToDesktop(5)
+ }
+return
+
++#6::
+ if(lock = 0)
+ {
+ lock = 1
+ SendActiveToDesktop(6)
+ }
+return
+
++#7::
+ if(lock = 0)
+ {
+ lock = 1
+ SendActiveToDesktop(7)
+ }
+return
+
++#8::
+ if(lock = 0)
+ {
+ lock = 1
+ SendActiveToDesktop(8)
+ }
+return
+
++#9::
+ if(lock = 0)
+ {
+ lock = 1
+ SendActiveToDesktop(9)
+ }
+return
+
+; switch to the desktop with the given index number
+SwitchToDesktop(newDesktop)
+{
+ global
+
+ WinGetActiveTitle, curWin
+
+ ; Removes the chance of getting Start Menu Shadow Frozen on Screen
+ if(curWin = "")
+ WinActivate, Program Manager
+
+ ; Removes the chance of getting Tray or Tooltip shadows frozen on screen
+ ToolTip
+ TrayTip
+ WinClose, ahk_class SysShadow
+
+ if (curDesktop <> newDesktop)
+ {
+ GetCurrentWindows(curDesktop)
+ ShowHideWindows(curDesktop, false)
+ ShowHideWindows(newDesktop, true)
+ activate_window := % active_id%newDesktop%
+ WinActivate, ahk_id %activate_window%
+ curDesktop := newDesktop
+ }
+
+ lock = 0
+ return
+}
+
+; sends the given window from the current desktop to the given desktop
+SendToDesktop(windowID, newDesktop)
+{
+ global
+ if (curDesktop <> newDesktop)
+ {
+ RemoveWindowID(curDesktop, windowID)
+
+ ; add window to destination desktop
+ windows%newDesktop% += 1
+ i := windows%newDesktop%
+
+ windows%newDesktop%%i% := windowID
+
+ WinHide, ahk_id %windowID%
+ Send, {ALT DOWN}{TAB}{ALT UP} ; activate the right window
+ }
+}
+
+; sends the currently active window to the given desktop
+SendActiveToDesktop(newDesktop)
+{
+
+ global
+
+ WinGet, id, ID, A
+
+ WinGetActiveTitle, curWin
+
+ ; sleep, 20
+
+ ; If Window Does not have a title, do not send it
+ if( (curWin = "") || (curWin = "Program Manager"))
+ {
+ lock = 0
+ ; sleep, 100
+ return
+ }
+
+ SendToDesktop(id, newDesktop)
+ ; sleep, 100
+ lock = 0
+}
+
+; removes the given window id from the desktop <desktopIdx>
+RemoveWindowID(desktopIdx, ID)
+{
+ global
+ Loop, % windows%desktopIdx%
+ {
+ if (windows%desktopIdx%%A_Index% = ID)
+ {
+ windows%desktopIdx%%A_Index%= ;Emiel: just empty the array element, array will be emptied by next switch anyway
+ Break
+ }
+ }
+}
+
+; this builds a list of all currently visible windows in stores it in desktop <index>
+GetCurrentWindows(index)
+{
+ global
+ WinGet, active_id%index%, ID, A ; get the current active window
+ emptyString =
+ StringSplit, windows%index%, emptyString ; delete the entire windows_index_ array
+ WinGet, windows%index%, List,,, Program Manager ; get list of all visible windows
+
+ ; remove windows which we want to see on all virtual desktops
+ Loop, % windows%index%
+ {
+ id := % windows%index%%A_Index%
+ WinGetClass, windowClass, ahk_id %id%
+ if windowClass = Shell_TrayWnd ; remove task bar window id
+ windows%index%%A_Index%= ; just empty the array element, array will be emptied by next switch anyway
+ if windowClass = #32770 ; we also want multimontaskbar on all virtual desktops
+ windows%index%%A_Index%= ; just empty the array element, array will be emptied by next switch anyway
+ if windowClass = cygwin/x X rl-xosview-XOsview-0 ; xosviews e.d.
+ windows%index%%A_Index%=
+ if windowClass = cygwin/x X rl-xosview-XOsview-1 ; xosviews e.d.
+ windows%index%%A_Index%=
+ if windowClass = MozillaUIWindowClass ; Mozilla thunderbird
+ {
+ WinGet, ExStyle, ExStyle, ahk_id %id%
+ if (ExStyle & 0x8) ; 0x8 is WS_EX_TOPMOST.
+ windows%index%%A_Index%=
+ }
+ if alwaysShow%id% = 1
+ windows%index%%A_Index%=
+ }
+}
+
+; if show=true then shows windows of desktop %index%, otherwise hides them
+ShowHideWindows(index, show)
+{
+ global
+
+ Loop, % windows%index%
+ {
+ id := % windows%index%%A_Index%
+ if show
+ WinShow, ahk_id %id%
+ else
+ WinHide, ahk_id %id%
+ }
+}
+
+
+;;;;;;;;;;;
+; Cleanup ;
+;;;;;;;;;;;
+
+CleanUp:
+ ; show all windows from all desktops on exit
+ Loop, %numDesktops%
+ ShowHideWindows(A_Index, true)
+ ; Unset focus follows mouse
+ DllCall("SystemParametersInfo",UInt,0x1001,UInt,0,UInt,0,UInt,1 | 2)
+ ; Display message
+ if A_ExitReason in Logoff,Shutdown
+ {
+ MsgBox, 0x1030, USB-Stick, Stick nicht vergessen!, 5
+ }
+ ExitApp