Jump to content

Virtual Desktop Script


Dampe
 Share

Recommended Posts

Wrote it to use at work.

Change the hotkeys at the top.

#include <array.au3>

Local $Win_Max_Number = 4
Local $Key_Forward = "{PAUSE}"
Local $Key_Backward = "{HOME}"
Local $Window_Array[5][25]
Local $Window_Current_Arr = 1
Local $Window_Current_Active = 1

Local $Dll_User_32 = DllOpen("user32.dll")
HotKeySet($Key_Forward, "_ScreenForward")
HotKeySet($Key_Backward, "_ScreenBackward")

_GenerateWindowArray()

While 1

    Sleep(50)
    _UpdateWindowArray()

WEnd

Func _GenerateWindowArray()

    $var = WinList()
    For $i = 1 To $var[0][0]
        If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
            $Window_Array[$Window_Current_Active][$Window_Current_Arr] = $var[$i][1]
            $Window_Current_Arr += 1
        EndIf
    Next

EndFunc   ;==>_GenerateWindowArray

Func _UpdateWindowArray()

    For $x = 1 to 4
        For $i = 1 to 24
            If not WinExists ($Window_Array[$x][$i]) Then
                $Window_Array[$x][$i] = ""
                $Window_Current_Arr -= 1
            EndIf
        Next
    Next

    $var = WinList()
    For $i = 1 To $var[0][0]
        If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
            If _ArraySearch($Window_Array, $var[$i][1]) = -1 Then
                $Window_Array[$Window_Current_Active][$Window_Current_Arr] = $var[$i][1]
                $Window_Current_Arr += 1
            EndIf
        EndIf
    Next

EndFunc

Func _ScreenForward()

    If $Window_Current_Active < $Win_Max_Number Then
        $Window_Current_Active += 1
        ConsoleWrite ("Screen #: " & $Window_Current_Active & @CRLF)

        For $i = 1 to 24
            If $Window_Array[$Window_Current_Active-1][$i] <> "" Then
                _SetWindowState($Window_Array[$Window_Current_Active-1][$i], 0)
            EndIf
        Next

        For $i = 1 to 24
        If $Window_Array[$Window_Current_Active][$i] <> "" Then
                _SetWindowState($Window_Array[$Window_Current_Active][$i], 1)
            EndIf
        Next

    EndIf

EndFunc   ;==>_ScreenForward

Func _ScreenBackward()

    If $Window_Current_Active > 1 Then
        $Window_Current_Active -= 1
        ConsoleWrite ("Screen #: " & $Window_Current_Active & @CRLF)

        For $i = 1 to 24
            If $Window_Array[$Window_Current_Active+1][$i] <> "" Then
                _SetWindowState($Window_Array[$Window_Current_Active+1][$i], 0)
            EndIf
        Next

        For $i = 1 to 24
        If $Window_Array[$Window_Current_Active][$i] <> "" Then
                _SetWindowState($Window_Array[$Window_Current_Active][$i], 1)
            EndIf
        Next

    EndIf

EndFunc   ;==>_ScreenBackward

Func _SetWindowState($hWnd, $sCode)

    DllCall($Dll_User_32, "bool", "ShowWindow", "HWND", $hWnd, "int", $sCode)

EndFunc   ;==>_SetWindowState

Func IsVisible($handle)

    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf

EndFunc   ;==>IsVisible
Link to comment
Share on other sites

Hello Dampe,

Nice idea for certain occasions or quick profile swapping. However I have found a couple problems.

Minor Problems

1. on the other virtual desktops, the desktop icons disappear.

2. once the start screen has been opened, it leaves a minor shadow behind when closed.

Major Problem: I closed the script while on a Virtual Desktop, Now all of my desktop icons and configuration is gone. Not to worry for me, I back up my desktop.

Maybe should include an exit function, that will deliver you back to the main desktop, or a way to duplicate desktop on the virtual desktops.

Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

@Dampe

I've already tried to do it on win7 with an other method and it does not work.

FireFox.

What? Yes it does.

I fixed the script here.

#include <array.au3>

Local $Win_Max_Number = 4
Local $Key_Forward = "{PAUSE}"
Local $Key_Backward = "{HOME}"
Local $Window_Array[5][25]
Local $Window_Current_Arr = 1
Local $Window_Current_Active = 1

OnAutoItExitRegister( "_Au3Exit" )

Local $Dll_User_32 = DllOpen("user32.dll")
HotKeySet($Key_Forward, "_ScreenForward")
HotKeySet($Key_Backward, "_ScreenBackward")

_GenerateWindowArray()

While 1

    Sleep(50)
    _UpdateWindowArray()

WEnd

Func _GenerateWindowArray()

    $var = WinList()
    For $i = 1 To $var[0][0]
        If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
            If $var[$i][0] <> "Start" AND $var[$i][0] <> "Program Manager" Then
                $Window_Array[$Window_Current_Active][$Window_Current_Arr] = $var[$i][1]
                $Window_Current_Arr += 1
            EndIf

        EndIf
    Next

EndFunc   ;==>_GenerateWindowArray

Func _UpdateWindowArray()

    For $x = 1 to 4
        For $i = 1 to 24
            If not WinExists ($Window_Array[$x][$i]) Then
                $Window_Array[$x][$i] = ""
                $Window_Current_Arr -= 1
            EndIf
        Next
    Next

    $var = WinList()
    For $i = 1 To $var[0][0]
        If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
            If $var[$i][0] <> "Start" AND $var[$i][0] <> "Program Manager" Then
                If _ArraySearch($Window_Array, $var[$i][1]) = -1 Then
                    $Window_Array[$Window_Current_Active][$Window_Current_Arr] = $var[$i][1]
                    $Window_Current_Arr += 1
                EndIf
            EndIf
        EndIf
    Next

EndFunc

Func _ScreenForward()

    If $Window_Current_Active < $Win_Max_Number Then
        $Window_Current_Active += 1
        ConsoleWrite ("Screen #: " & $Window_Current_Active & @CRLF)

        For $i = 1 to 24
            If $Window_Array[$Window_Current_Active-1][$i] <> "" Then
                _SetWindowState($Window_Array[$Window_Current_Active-1][$i], 0)
            EndIf
        Next

        For $i = 1 to 24
        If $Window_Array[$Window_Current_Active][$i] <> "" Then
                _SetWindowState($Window_Array[$Window_Current_Active][$i], 1)
            EndIf
        Next

    EndIf

EndFunc   ;==>_ScreenForward

Func _ScreenBackward()

    If $Window_Current_Active > 1 Then
        $Window_Current_Active -= 1
        ConsoleWrite ("Screen #: " & $Window_Current_Active & @CRLF)

        For $i = 1 to 24
            If $Window_Array[$Window_Current_Active+1][$i] <> "" Then
                _SetWindowState($Window_Array[$Window_Current_Active+1][$i], 0)
            EndIf
        Next

        For $i = 1 to 24
        If $Window_Array[$Window_Current_Active][$i] <> "" Then
                _SetWindowState($Window_Array[$Window_Current_Active][$i], 1)
            EndIf
        Next

    EndIf

EndFunc   ;==>_ScreenBackward

Func _SetWindowState($hWnd, $sCode)

    DllCall($Dll_User_32, "bool", "ShowWindow", "HWND", $hWnd, "int", $sCode)

EndFunc   ;==>_SetWindowState

Func IsVisible($handle)

    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf

EndFunc   ;==>IsVisible

Func _Au3Exit()

    For $x = 1 to $Win_Max_Number
        For $i = 1 to 24
            _SetWindowState($Window_Array[$x][$i], 1)
        Next
    Next
    DllClose ($Dll_User_32)

EndFunc
Link to comment
Share on other sites

Hmmm, I got a suggestion, dunno if its possible.

Maybe a PIP function?

Like on TV's, where you can view 1 channel in most of the screen size and a second in a small section in the bottom right?

I like watching movies while doing something and this could be handy if I could watch it on one VD and do other things on the other while still viewing that screen.

Thanks, love the script by the way, how'd you come up with this and figure out the commands?

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

Hmmm, I got a suggestion, dunno if its possible.

Maybe a PIP function?

Like on TV's, where you can view 1 channel in most of the screen size and a second in a small section in the bottom right?

I like watching movies while doing something and this could be handy if I could watch it on one VD and do other things on the other while still viewing that screen.

Thanks, love the script by the way, how'd you come up with this and figure out the commands?

I guess it would be possible but pretty impracticable.

If you want to watch a movie at the same time, have a look at VLC Media player.

Pretty sure you can right click and set window to be always on top which would allow you to do other things on the computer whilst watching a movie..

I use linux at home and quite a few linux desktop enviroments support virtual desktops, so I wanted one for work.

I guess I learn the commands from years of programming and knowledge of the windows internal functions.

I was originally using the autoit setwindowstate() function but it was too slow, hence using the user_32.dll function instead.

Peace

Link to comment
Share on other sites

I was originally using the autoit setwindowstate() function but it was too slow, hence using the user_32.dll function instead.

Slow how? ;)

It should be faster than any UD function made for similar purposes. You probably should have add Opt("WinWaitDelay", 0) because that function, WinSetState that is, obeys this option setting.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Slow how? ;)

It should be faster than any UD function made for similar purposes. You probably should have add Opt("WinWaitDelay", 0) because that function, WinSetState that is, obeys this option setting.

Ah that would make sense :)

Link to comment
Share on other sites

Hmm, that sucks, I was looking forward to that ;)

Maybe one day I can try and do it myself.

Either way, nice script.

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

  • 7 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...