VD.ahk : Virtual Desktop (move window, go to VD of your choice instantly, get Which VD you are in, etc.)

Post your working scripts, libraries and tools
MrDoge
Posts: 61
Joined: 27 Apr 2020, 21:29

VD.ahk : Virtual Desktop (move window, go to VD of your choice instantly, get Which VD you are in, etc.)

17 Nov 2020, 21:43

you should put VD.ahk in your standard library: for me it's "C:\Program Files\AutoHotkey\lib"
https://www.autohotkey.com/docs/Functions.htm#lib

I've moved the code to github:
https://github.com/FuPeiJiang/VD.ahk

the function library is : "VD.ahk":
https://raw.githubusercontent.com/FuPeiJiang/VD.ahk/master/VD.ahk

some examples (change the wintitles to your choice) "VD examples.ahk":
https://raw.githubusercontent.com/FuPeiJiang/VD.ahk/master/VD%20examples.ahk

Just run the examples, everything explained inside



Edit:
added ; VD_getCount() ;this will return the number of virtual desktops you currently have

Edit 2: FIXES:
1)annoying flash 2)VD_sendToCurrentDesktop crash 3)global vars

1) switching desktop causes focused window to blink in taskbar
https://github.com/mzomparelli/zVirtualDesktop/issues/59#issuecomment-317613971

so I winactivate the taskbar and then when I arrive at new Virtual Desktop, I emulate alt-tab.

2) Added VD_isValidWindow(hWnd) to only select valid window : It wasn't working for ("ahk_exe devenv.exe")

3) renamed some global vars

Edit 3: FIXED: sometimes SwitchDesktop will altTab into another window
after arriving, winactivate taskbar before altTab

Edit 4: completely fixed VD_SwitchDesktop(): altTab, not switching
renamed VD_getCurrentVirtualDesktop() -> VD_getCurrentDesktop()
removed VD_AltTab()
added VD_isWindowFullScreen(winTitle)
added VD_getCurrentIVirtualDesktop()

WinMinimize, ahk_class Shell_TrayWnd
instead of altTabing

SwitchDesktop twice when in fullscreen apps
Last edited by MrDoge on 05 Jan 2021, 20:47, edited 6 times in total.
MrDoge
Posts: 61
Joined: 27 Apr 2020, 21:29

Re: VD.ahk : Virtual Desktop (move window, go to VD of your choice instantly, get Which VD you are in, etc.)

18 Nov 2020, 14:17

can I avoid calling VD.init() if I used a class instead ?
can the class call VD.init() by itself when I #include it ?
by call VD.init(), I mean assign the variables

reasons I don't like using class :
1)non global vars, so I need to this.Var instead of Var
2)I would have to
#include <VD>
VD.init()

instead of

VD_init()
User avatar
kczx3
Posts: 1224
Joined: 06 Oct 2015, 21:39

Re: VD.ahk : Virtual Desktop (move window, go to VD of your choice instantly, get Which VD you are in, etc.)

18 Nov 2020, 21:43

You may be able to avoid it if the class is used in a static fashion. You’d just have to have an internal property to determine if it has been initialized yet, and if not, self initialize.
BoBo
Posts: 4142
Joined: 13 May 2014, 17:15

Re: VD.ahk : Virtual Desktop (move window, go to VD of your choice instantly, get Which VD you are in, etc.)

19 Nov 2020, 01:08

@MrDoge - Looks promising! Just out of curiosity (I‘ve might have missed it), is there any indicator (like array.Length() for arrays) that is telling us the number of virtual screens/desktops currently available?

PS. I’m thinking about to use it with this: matricapp.com 8-)
MrDoge
Posts: 61
Joined: 27 Apr 2020, 21:29

Re: VD.ahk : Virtual Desktop (move window, go to VD of your choice instantly, get Which VD you are in, etc.)

19 Nov 2020, 11:13

@kczx3 what is a non-static fashion ?

I could check it using this (in front of every function) :
IfNotEqual, true, this.initialized, this.init()

but what if the init() takes a long time... I want to call it at the start of script (at the end of the autoexecute section), instead of calling init() when I need to use another function.
is there a onInclude() method ? so it is called when the class is included, instead of __New() (which is called when a new instance is created)
well this isn't that bad, it's one 1 line more than function library
#include <VD>
VD := new VD()

I don't see a problem with global variables, does it slow down the script ?

@BoBo
thanks for telling me, I haven't thought about this.
the script has A LOT of duplicate code, but it works so ...

I've edited the 1st post, added VD_getCount()

what extra use can matricapp.com provide if I already have hotkeys ? (extra buttons ?)
User avatar
kczx3
Posts: 1224
Joined: 06 Oct 2015, 21:39

Re: VD.ahk : Virtual Desktop (move window, go to VD of your choice instantly, get Which VD you are in, etc.)

19 Nov 2020, 15:08

Every single one of those functions are global. So if any of your variable names clash with a consumers, you will overwrite their variables, or they could overwrite yours.
BoBo
Posts: 4142
Joined: 13 May 2014, 17:15

Re: VD.ahk : Virtual Desktop (move window, go to VD of your choice instantly, get Which VD you are in, etc.)

19 Nov 2020, 15:20

@MrDoge -
what extra use can matricapp.com provide if I already have hotkeys ? (extra buttons ?)
Matric is providing an 'auto switcher-option that will swap to a predefined deck (ie for OBS/YouTube/Netflix/...) once its assigned application at the PC gets the focus.
That might be interesting for those who are not able/willing to remember a thousand different hotkeys (that might often end up duplicated if used for different applications).
So you can use whatever Android device to remote control whatever application on your PC. And yes, these (button) decks can be created/designed by yourself.

Thx for implementing that feature, much appreciated :)

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 14 guests