ioa747 Posted June 27, 2024 Posted June 27, 2024 (edited) Press F1 to cycle between opened windows in the screen 1 or press F2 to cycle between opened windows in the screen 2, and so on. (outline version) expandcollapse popup#include <MsgBoxConstants.au3> #include <WinAPISysWin.au3> #include <WinAPIGdi.au3> #include <Array.au3> _RegisterHotKeys(True) While 1 Sleep(100) WEnd ;-------------------------------------------------------------------------------------------------------------------------------- Func HotKeyPressed() Local $hWnds, $id _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 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 $aPos = WinGetPos($aWindows[$i][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") Else HotKeySet("{F1}") HotKeySet("{F2}") HotKeySet("{F3}") HotKeySet("{F4}") HotKeySet("{F5}") HotKeySet("{F6}") EndIf EndFunc ;==>_RegisterHotKeys ;-------------------------------------------------------------------------------------------------------------------------------- Please, every comment is appreciated! leave your comments and experiences here! Thank you very much Edited June 27, 2024 by ioa747 I know that I know nothing
ioa747 Posted June 30, 2024 Author Posted June 30, 2024 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) expandcollapse popup; https://www.autoitscript.com/forum/topic/212015-multiple-screen-windows-switch-hot-key/ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #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 ;--------------------------------------------------------------------------------------- I know that I know nothing
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now