Advertisement
User57

MultipleScreen_WindowsSwitch_HotKey

Jun 30th, 2024 (edited)
153
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.58 KB | None | 0 0
  1. ;Script Version: 2.0
  2. #include <MsgBoxConstants.au3>
  3. #include <WinAPISysWin.au3>
  4. #include <WinAPIGdi.au3>
  5. #include <Array.au3>
  6. #include <Misc.au3>
  7.  
  8. Global $sIniFile = @ScriptDir & '\' & StringTrimRight(@ScriptName, 4) & '.ini'
  9.  
  10. _RegisterHotKeys(True)
  11.  
  12. While 1
  13.     Sleep(100)
  14. WEnd
  15.  
  16. ;---------------------------------------------------------------------------------------
  17. Func HotKeyPressed()
  18.     Local $hWnds, $id, $sPos, $a
  19.     _RegisterHotKeys(False)
  20.     Switch @HotKeyPressed ; The last hotkey pressed.
  21.         Case "{F1}"
  22.             $id = 1
  23.         Case "{F2}"
  24.             $id = 2
  25.         Case "{F3}"
  26.             $id = 3
  27.         Case "{F4}"
  28.             $id = 4
  29.         Case "{F5}"
  30.             $id = 5
  31.         Case "{F6}"
  32.             $id = 6
  33.         Case "{HOME}"
  34.             Local $aArray = IniReadSection($sIniFile, "WinTitle_XYWH")
  35.             If Not @error Then
  36.                 ToolTip(" ", Default, Default, " Restore position", 1)
  37.                 For $i = 1 To $aArray[0][0]
  38.                     If WinExists($aArray[$i][0]) Then
  39.                         $a = StringSplit($aArray[$i][1], ";")
  40.                         If $a[0] = 4 Then
  41.                             WinMove($aArray[$i][0], "", $a[1], $a[2], $a[3], $a[4])
  42.                             Local $aPos = WinGetPos($aArray[$i][0])
  43.                             ;Recheck
  44.                             If $aPos[0] <> $a[1] Or $aPos[1] <> $a[2] Or $aPos[2] <> $a[3] Or $aPos[3] <> $a[4] Then
  45.                                 WinMove($aArray[$i][0], "", $a[1], $a[2], $a[3], $a[4])
  46.                             EndIf
  47.                         EndIf
  48.                     EndIf
  49.                 Next
  50.             EndIf
  51.             Sleep(2000)
  52.             _RegisterHotKeys(True)
  53.             ToolTip("")
  54.             Return
  55.  
  56.         Case "^{HOME}"
  57.             Local $hW = WinGetHandle("[ACTIVE]")
  58.             Local $sTitle = WinGetTitle($hW)
  59.             $a = WinGetPos($hW)
  60.             $sPos = $a[0] & ";" & $a[1] & ";" & $a[2] & ";" & $a[3]
  61.             IniWrite($sIniFile, "WinTitle_XYWH", $sTitle, $sPos)
  62.             ToolTip(" ", Default, Default, " Save position", 1)
  63.             Sleep(2000)
  64.             _RegisterHotKeys(True)
  65.             ToolTip("")
  66.             Return
  67.     EndSwitch
  68.  
  69.     $hWnds = _EnumWindows("\\.\DISPLAY" & $id)
  70.     If $hWnds[0][0] > 1 Then WinActivate($hWnds[$hWnds[0][0]][0])
  71.     _RegisterHotKeys(True)
  72.  
  73. EndFunc   ;==>HotKeyPressed
  74. ;---------------------------------------------------------------------------------------
  75. Func _EnumWindows($sDisplay)
  76.     Local $aWindows = _WinAPI_EnumWindowsTop()
  77.     Local $aResult[1][3]
  78.     $aResult[0][0] = $aWindows[0][0] ; Window Handle
  79.     $aResult[0][1] = "Window Class"  ; Window Class
  80.     $aResult[0][2] = "Window Title"  ; Window Title
  81.     Local $idx = 0
  82.     For $i = 1 To $aWindows[0][0]
  83.         Local $hMonitor = _WinAPI_MonitorFromWindow($aWindows[$i][0], $MONITOR_DEFAULTTONEAREST)
  84.         Local $aData = _WinAPI_GetMonitorInfo($hMonitor)
  85.         Local $sTitle = WinGetTitle($aWindows[$i][0])
  86.         ;skip untitled
  87.         If $aData[3] = $sDisplay And $sTitle <> "" Then
  88.             ;skip if is in class * <-- Blacklisted Classes
  89.             Switch $aWindows[$i][1] ; class
  90.                 Case "Windows.UI.Core.CoreWindow", "CEF-OSC-WIDGET", "Progman"
  91.                     ContinueLoop
  92.             EndSwitch
  93.             ReDim $aResult[UBound($aResult) + 1][3]
  94.             $idx += 1
  95.             $aResult[$idx][0] = $aWindows[$i][0] ; Window Handle
  96.             $aResult[$idx][1] = $aWindows[$i][1] ; Window Class
  97.             $aResult[$idx][2] = $sTitle          ; Window Title
  98.         EndIf
  99.     Next
  100.     $aResult[0][0] = UBound($aResult) - 1
  101.     Return $aResult
  102. EndFunc   ;==>_EnumWindows
  103. ;---------------------------------------------------------------------------------------
  104. Func _RegisterHotKeys($bRegister = True)
  105.     If $bRegister = True Then
  106.         HotKeySet("{F1}", "HotKeyPressed")
  107.         HotKeySet("{F2}", "HotKeyPressed")
  108.         HotKeySet("{F3}", "HotKeyPressed")
  109.         HotKeySet("{F4}", "HotKeyPressed")
  110.         HotKeySet("{F5}", "HotKeyPressed")
  111.         HotKeySet("{F6}", "HotKeyPressed")
  112.         HotKeySet("{HOME}", "HotKeyPressed")
  113.         HotKeySet("^{HOME}", "HotKeyPressed")
  114.     Else
  115.         HotKeySet("{F1}")
  116.         HotKeySet("{F2}")
  117.         HotKeySet("{F3}")
  118.         HotKeySet("{F4}")
  119.         HotKeySet("{F5}")
  120.         HotKeySet("{F6}")
  121.         HotKeySet("{HOME}")
  122.         HotKeySet("^{HOME}")
  123.     EndIf
  124. EndFunc   ;==>_RegisterHotKeys
  125. ;---------------------------------------------------------------------------------------
Advertisement
Comments
  • User57
    1 year
    # text 0.42 KB | 0 0
    1. switch between different opened windows/apps that are currently expanded in certain monitors.
    2.  
    3. 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.
    4.  
    5. I added 2 more hotkeys
    6. ctrl + Home to save the active window position
    7. Home to restore all the saved windows in their position (which are open)
Add Comment
Please, Sign In to add comment
Advertisement