Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Script Version: 2.0
- #include <MsgBoxConstants.au3>
- #include <WinAPISysWin.au3>
- #include <WinAPIGdi.au3>
- #include <Array.au3>
- #include <Misc.au3>
- Global $sIniFile = @ScriptDir & '\' & StringTrimRight(@ScriptName, 4) & '.ini'
- _RegisterHotKeys(True)
- While 1
- Sleep(100)
- WEnd
- ;---------------------------------------------------------------------------------------
- Func HotKeyPressed()
- Local $hWnds, $id, $sPos, $a
- _RegisterHotKeys(False)
- Switch @HotKeyPressed ; The last hotkey pressed.
- Case "{F1}"
- $id = 1
- Case "{F2}"
- $id = 2
- Case "{F3}"
- $id = 3
- Case "{F4}"
- $id = 4
- Case "{F5}"
- $id = 5
- Case "{F6}"
- $id = 6
- Case "{HOME}"
- Local $aArray = IniReadSection($sIniFile, "WinTitle_XYWH")
- If Not @error Then
- ToolTip(" ", Default, Default, " Restore position", 1)
- For $i = 1 To $aArray[0][0]
- If WinExists($aArray[$i][0]) Then
- $a = StringSplit($aArray[$i][1], ";")
- If $a[0] = 4 Then
- WinMove($aArray[$i][0], "", $a[1], $a[2], $a[3], $a[4])
- Local $aPos = WinGetPos($aArray[$i][0])
- ;Recheck
- If $aPos[0] <> $a[1] Or $aPos[1] <> $a[2] Or $aPos[2] <> $a[3] Or $aPos[3] <> $a[4] Then
- WinMove($aArray[$i][0], "", $a[1], $a[2], $a[3], $a[4])
- EndIf
- EndIf
- EndIf
- Next
- EndIf
- Sleep(2000)
- _RegisterHotKeys(True)
- ToolTip("")
- Return
- Case "^{HOME}"
- Local $hW = WinGetHandle("[ACTIVE]")
- Local $sTitle = WinGetTitle($hW)
- $a = WinGetPos($hW)
- $sPos = $a[0] & ";" & $a[1] & ";" & $a[2] & ";" & $a[3]
- IniWrite($sIniFile, "WinTitle_XYWH", $sTitle, $sPos)
- ToolTip(" ", Default, Default, " Save position", 1)
- Sleep(2000)
- _RegisterHotKeys(True)
- ToolTip("")
- Return
- EndSwitch
- $hWnds = _EnumWindows("\\.\DISPLAY" & $id)
- If $hWnds[0][0] > 1 Then WinActivate($hWnds[$hWnds[0][0]][0])
- _RegisterHotKeys(True)
- EndFunc ;==>HotKeyPressed
- ;---------------------------------------------------------------------------------------
- Func _EnumWindows($sDisplay)
- Local $aWindows = _WinAPI_EnumWindowsTop()
- Local $aResult[1][3]
- $aResult[0][0] = $aWindows[0][0] ; Window Handle
- $aResult[0][1] = "Window Class" ; Window Class
- $aResult[0][2] = "Window Title" ; Window Title
- Local $idx = 0
- For $i = 1 To $aWindows[0][0]
- Local $hMonitor = _WinAPI_MonitorFromWindow($aWindows[$i][0], $MONITOR_DEFAULTTONEAREST)
- Local $aData = _WinAPI_GetMonitorInfo($hMonitor)
- Local $sTitle = WinGetTitle($aWindows[$i][0])
- ;skip untitled
- If $aData[3] = $sDisplay And $sTitle <> "" Then
- ;skip if is in class * <-- Blacklisted Classes
- Switch $aWindows[$i][1] ; class
- Case "Windows.UI.Core.CoreWindow", "CEF-OSC-WIDGET", "Progman"
- ContinueLoop
- EndSwitch
- ReDim $aResult[UBound($aResult) + 1][3]
- $idx += 1
- $aResult[$idx][0] = $aWindows[$i][0] ; Window Handle
- $aResult[$idx][1] = $aWindows[$i][1] ; Window Class
- $aResult[$idx][2] = $sTitle ; Window Title
- EndIf
- Next
- $aResult[0][0] = UBound($aResult) - 1
- Return $aResult
- EndFunc ;==>_EnumWindows
- ;---------------------------------------------------------------------------------------
- Func _RegisterHotKeys($bRegister = True)
- If $bRegister = True Then
- HotKeySet("{F1}", "HotKeyPressed")
- HotKeySet("{F2}", "HotKeyPressed")
- HotKeySet("{F3}", "HotKeyPressed")
- HotKeySet("{F4}", "HotKeyPressed")
- HotKeySet("{F5}", "HotKeyPressed")
- HotKeySet("{F6}", "HotKeyPressed")
- HotKeySet("{HOME}", "HotKeyPressed")
- HotKeySet("^{HOME}", "HotKeyPressed")
- Else
- HotKeySet("{F1}")
- HotKeySet("{F2}")
- HotKeySet("{F3}")
- HotKeySet("{F4}")
- HotKeySet("{F5}")
- HotKeySet("{F6}")
- HotKeySet("{HOME}")
- HotKeySet("^{HOME}")
- EndIf
- EndFunc ;==>_RegisterHotKeys
- ;---------------------------------------------------------------------------------------
Advertisement
Comments
-
- switch between different opened windows/apps that are currently expanded in certain monitors.
- For example I have 6 monitors. I want to press F1 to toggle between opened windows/apps in the screen 1 or press F2 to toggle between opened windows/apps in the screen 2, and so on.
- I added 2 more hotkeys
- ctrl + Home to save the active window position
- Home to restore all the saved windows in their position (which are open)
Add Comment
Please, Sign In to add comment
Advertisement