0
UPDATED-STATEMENT: 20181118@205016@SUN A suggestion was made to manually focus the Virtual Desktop of my choice, but this eliminates me from doing other tasks on another Virtual Desktop. Still waiting for a valid take-care-ofitself solution.
UPDATED-STATEMENT: 20181118@210851@SUN There is no way autohotkey can work with moving apps to a specific Virtual Desktop on it's own without dll-calls (*see below*). In other words, the use of dll-files is required for the time being that is Windows language and not as convenient as an ahk-statement. Who knows, maybe ahk can implement this function someday to keep it lightweight and add it to their statement-library.
UPDATED-TATEMENT: 20190509@212923@THU @Shayan suggested sdias-win10virtualdesktopenhancer as a way to manage windows and virtual desktops.
SPECIFICATION:
win10_1803_17134.407
autohotkeyahk_1.1.30.00_20180822

After the 5-month idle time for this topic i've now stopped using virtual desktops.

Virtual Desktops doesn't make navigation any easier, perhaps the clear view of the wallpaper will be enjoyed by some, but not me.

WHY I USE AHK

Using Autohotkey in Windows 10 to open up frequently used apps which will not duplicate opening up a program if it has already launched (IfWinNotExist). Then, move them to where I prefer each app to be (WinMove). I have set a timer (Sleep) because some apps open up slower than others (I would be interested to know if there is a better way to do this). I like ahk for how lightweight it is, but there's Windows 10 related functions that aren't documented from them like Virtual Desktop involvement.

PROBLEM

Problem is that there isn't a way to use WinMove for specifying a Virtual Desktop for win10 to launch an application in. So I struggle running my frequentlyusedapps-script and going into another Virtual Desktop to open up other apps simultaneously. This is because what ever Virtual Desktop i'm focusing on is what my frequentlyusedapps-script will move the window to.

QUESTION

How to have autohotkey move an application to a Virtual Desktop of my choice? I don't think it's possible with ahk-WinMove If the virtualdesktop-number isn't created then the script will obviously fail to move the app, but this isn't my focus just yet. I could otherwise create the appropriate number of Virtual Desktops prior to launching my frequentlyusedapps-script. What I mean by having a way for ahk to achieve this is to be pure ahk code and not fork/branch that will probably be not updated for the unfortunate reasons. If it does have to come from a branched project then let's discuss what ahk elements they're using to involve Virtual Desktop to move windows to a specific one.

!^+o::
  IfWinNotExist, ahk_exe program1.exe
    Run "C:\Dir\program1.exe"
    WinWait, ahk_exe program1.exe
    WinMove, ahk_exe program1.exe,, 953, 61, 967, 1019
    TrayTip, openfrequentlyusedapps, ok, 1,
  IfWinNotExist, ahk_exe program2.exe
    Run "C:\Dir\program2.exe"
    WinWait, ahk_exe program2.exe
    WinMove, ahk_exe program2.exe,, -7, 61, 813, 516
    TrayTip, openfrequentlyusedapps, ok, 1,

SOLUTION

  • As per @miroxlav, "there is no way Autohotkey can do this with their current statements." Although not impossible, but requires more effort as it's now Windows language is using ahk w/ dll-calls.
    • It would help a lot of someone is able to show how this even works
NOTE
  • 1
  • 1
    I wanted to stick with the roots of ahk and not a branch away from it's core (due to branding). What do you think this yet another enhancer uses to move windows to another desktop? Because I noticed the use of dll-files which isn't lightweight anymore. – fohrums Nov 17 '18 at 22:31
  • What's wrong with using dll-files to facilitate or even make possible the execution of tasks if they come from a secure site?. No program can execute all its functions and various features using its own modules or resources. And dll-files are files that contains specific code that many installed programs use and share. – user3419297 Nov 18 '18 at 19:54
  • How do you even know those dll-files online are even secured? If getting dll-files from another software, then that only means you have to have the software which is impossible to obtain if you don't have it in the first place especially if you don't have internet at the time being. I really meant it when I talked about using ahk and it being "lightweight". I just need help on using dll-calls and what dll-files are required as dependencies to move windows to a specific virtual desktop. – fohrums Nov 18 '18 at 21:29
  • @fohrums Use Windows 10 Virtual Desktop Enhancer it has all the features you need. – Shayan Apr 25 at 20:31
2

Go with keyboard shortcuts.

Inside the script, when you sequentially start your apps, in the middle of your sequence simply switch to the next desktop by sending Ctrl+Win+:

;here you run and position your windows
Run app1
Move app1  'etc.
WinWait app1window   'wait until app window is open

;switch to next desktop*  (see note below the code)
Send ^#{Right}

;opening apps on next desktop
Run app2
Move app2  'etc.

*) If you do not have that "next desktop" prepared at the time, send Ctrl+Alt+D instead to create and open it.

For more, see section Virtual desktops keyboard shortcuts in the official list of Windows keyboard shortcuts.


Update:

Functionality regarding other desktops as you request it is currently not present directly in AHK statements. You may be able to achieve it by using DLL calls from within the AHK.

  • That's an action after an action which only means I still have to be focused on the desktop I want the windows to so happen to land in once opened. This eliminates me from going into another virtual desktop simultaneously to do other tasks while I wait for slow apps to launch (but, thanks for letting me know about ahk-WinWait so I replaced ahk-Sleep with it instead). – fohrums Nov 18 '18 at 10:49
  • That's not a problem for me I don't know why it would be. Virtual Desktop is marvelous for being able to simulate working on multiple computers but using just a single rig. I don't know the limit of how many is workable, but I then would use another Virtual Desktop to continue opening up other apps. I hope this answers you're concern. – fohrums Nov 18 '18 at 11:00
  • Thanks for the help @miroxlav, I just needed to know that. I thought there was some hidden command that I had to dig up in order to achieve this, but it looks like it's farily new. I imagine AHK could make this possible some day as Windows 10 has been released for over 3-yrs now. Virtual Desktop doesn't seem like it's going to go away anytime soon so it's good I began this topic. – fohrums Nov 18 '18 at 11:08
1

Following this answer you will be able to move current window to your next/prev virtual desktop with Win1 / Win2.

You are going to need VirtualDesktopAccessor.

Depending on the version of Windows 10 you're using (you can check with winver, search in start menu), download the correct x64 release.

For exmaple if you're using 1803 download this.

Or if you're using 1809, download this.

Create a new ahk script and put the dll file you downloaded and the script you just created in a same folder.

copy paste this in your script:

#SingleInstance Force

VDALoc := A_ScriptDir "\VirtualDesktopAccessor.dll"

hVirtualDesktopAccessor := DllCall("LoadLibrary", Str, VDALoc, "Ptr") 
GoToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "GoToDesktopNumber", "Ptr")
GetCurrentDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "GetCurrentDesktopNumber", "Ptr")
MoveWindowToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "MoveWindowToDesktopNumber", "Ptr")
activeWindowByDesktop := {}

MoveCurrentWindowToPrevDesktop() {
    global MoveWindowToDesktopNumberProc, GoToDesktopNumberProc, activeWindowByDesktop, GetCurrentDesktopNumberProc
    current := DllCall(GetCurrentDesktopNumberProc, UInt)
    WinGet, activeHwnd, ID, A
    if (current = 0) {
        return
    } else {
        activeWindowByDesktop[current - 1] := 0 ; Do not activate
        DllCall(MoveWindowToDesktopNumberProc, UInt, activeHwnd, UInt, current - 1)
        Send, {Blind}{Ctrl Down}{LWin Down}{Left Down}{Left Up}{LWin Up}{Ctrl Up}
    }
    return
}

MoveCurrentWindowToNextDesktop() {
    global MoveWindowToDesktopNumberProc, GoToDesktopNumberProc, activeWindowByDesktop, GetCurrentDesktopNumberProc
    current := DllCall(GetCurrentDesktopNumberProc, UInt)
    WinGet, activeHwnd, ID, A
    if (current = 3) {
        return
    } else {
        activeWindowByDesktop[current + 1] := 0 ; Do not activate
        DllCall(MoveWindowToDesktopNumberProc, UInt, activeHwnd, UInt, current + 1)
        Send, {Blind}{Ctrl Down}{LWin Down}{Right Down}{Right Up}{LWin Up}{Ctrl Up}
    }
    return
}

#1::MoveCurrentWindowToPrevDesktop()
#2::MoveCurrentWindowToNextDesktop()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.