AUTOHOTKEY | WinMove | Virtual Desktop of choice
up vote
0
down vote
favorite
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.
SPECIFICATION:
win10_1803_17134.407
autohotkeyahk_1.1.30.00_20180822
Speed is everything if it does affect you sitting on your chair in front of a computer screen.
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:Dirprogram1.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:Dirprogram2.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
- What is Virtual Desktop?
- What is autohotkey?
- What hotkeys can I use with ahk?
- What is ahk-WinExist or IfWinNotExist?
- What is ahk-Sleep?
- What is ahk-WinMove?
- Why use ahk-Sleep over ahk-WinWait to not do a single action until an app has been opened and ready to move via WinMove?
- Good question as I wasn't aware, but i'm using WinWait now and it's so much more efficient
windows-10 autohotkey virtual-desktop
add a comment |
up vote
0
down vote
favorite
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.
SPECIFICATION:
win10_1803_17134.407
autohotkeyahk_1.1.30.00_20180822
Speed is everything if it does affect you sitting on your chair in front of a computer screen.
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:Dirprogram1.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:Dirprogram2.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
- What is Virtual Desktop?
- What is autohotkey?
- What hotkeys can I use with ahk?
- What is ahk-WinExist or IfWinNotExist?
- What is ahk-Sleep?
- What is ahk-WinMove?
- Why use ahk-Sleep over ahk-WinWait to not do a single action until an app has been opened and ready to move via WinMove?
- Good question as I wasn't aware, but i'm using WinWait now and it's so much more efficient
windows-10 autohotkey virtual-desktop
1
Try github.com/sdias/win-10-virtual-desktop-enhancer
– user3419297
Nov 17 at 13:58
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 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 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 at 21:29
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.
SPECIFICATION:
win10_1803_17134.407
autohotkeyahk_1.1.30.00_20180822
Speed is everything if it does affect you sitting on your chair in front of a computer screen.
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:Dirprogram1.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:Dirprogram2.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
- What is Virtual Desktop?
- What is autohotkey?
- What hotkeys can I use with ahk?
- What is ahk-WinExist or IfWinNotExist?
- What is ahk-Sleep?
- What is ahk-WinMove?
- Why use ahk-Sleep over ahk-WinWait to not do a single action until an app has been opened and ready to move via WinMove?
- Good question as I wasn't aware, but i'm using WinWait now and it's so much more efficient
windows-10 autohotkey virtual-desktop
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.
SPECIFICATION:
win10_1803_17134.407
autohotkeyahk_1.1.30.00_20180822
Speed is everything if it does affect you sitting on your chair in front of a computer screen.
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:Dirprogram1.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:Dirprogram2.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
- What is Virtual Desktop?
- What is autohotkey?
- What hotkeys can I use with ahk?
- What is ahk-WinExist or IfWinNotExist?
- What is ahk-Sleep?
- What is ahk-WinMove?
- Why use ahk-Sleep over ahk-WinWait to not do a single action until an app has been opened and ready to move via WinMove?
- Good question as I wasn't aware, but i'm using WinWait now and it's so much more efficient
windows-10 autohotkey virtual-desktop
windows-10 autohotkey virtual-desktop
edited Nov 18 at 11:39
asked Nov 17 at 8:57
fohrums
76311
76311
1
Try github.com/sdias/win-10-virtual-desktop-enhancer
– user3419297
Nov 17 at 13:58
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 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 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 at 21:29
add a comment |
1
Try github.com/sdias/win-10-virtual-desktop-enhancer
– user3419297
Nov 17 at 13:58
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 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 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 at 21:29
1
1
Try github.com/sdias/win-10-virtual-desktop-enhancer
– user3419297
Nov 17 at 13:58
Try github.com/sdias/win-10-virtual-desktop-enhancer
– user3419297
Nov 17 at 13:58
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 at 22:31
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 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 at 19:54
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 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 at 21:29
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 at 21:29
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
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 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 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 at 11:08
add a comment |
up vote
0
down vote
Try this
#NoEnv
#SingleInstance Force
SetBatchLines -1
SetWorkingDir %A_ScriptDir%
main(), return
; Ctrl + number from 1 to 9
switch_to_desktop:
switchToDesktop(StrReplace(A_ThisHotkey, "^", , , 1) - 1)
Focus()
return
; Ctrl + Win + number from 1 to 9
move_A_to_desktop:
WinGet, active_id, ID, A
If !IsWindowOnCurrentVirtualDesktop(active_id)
return
IniRead, active_desktop, active_desktop.ini, active_desktop, desktop
WinHide ahk_id %active_id%
switchToDesktop(StrReplace(A_ThisHotkey, "^#", , , 1) - 1)
WinShow ahk_id %active_id%
switchToDesktop(active_desktop - 1)
return
; Ctrl + Shift + number from 1 to 9
move_A_and_switch_to_desktop:
WinGet, active_id, ID, A
If !IsWindowOnCurrentVirtualDesktop(active_id)
return
WinHide ahk_id %active_id%
switchToDesktop(StrReplace(A_ThisHotkey, "^+", , , 1) - 1)
WinShow ahk_id %active_id%
WinActivate, ahk_id %active_id%
Focus()
return
; https://autohotkey.com/boards/viewtopic.php?f=6&t=14881&hilit=Virtual+Desktop
switchToDesktop(idx) {
global ppDesktopManager, IID_IVirtualDesktop
DllCall(vtable(ppDesktopManager, 7), "Ptr", ppDesktopManager, "Ptr*", pDesktops)
if (pDesktops) {
DllCall(vtable(pDesktops, 4), "Ptr", pDesktops, "UInt", idx, "Ptr", &IID_IVirtualDesktop, "Ptr*", VirtualDesktop)
if (VirtualDesktop) {
DllCall(vtable(ppDesktopManager, 9), "Ptr", ppDesktopManager, "Ptr", VirtualDesktop)
ObjRelease(VirtualDesktop) ; I assume these should be freed
}
ObjRelease(pDesktops)
}
If (idx = "")
Index := 1
else
Index := idx +1
IniWrite, %Index%, active_desktop.ini, active_desktop, desktop
CoordMode, ToolTip, Screen
ToolTip, Desktop %Index%, (A_ScreenWidth -20), 0
}
main() {
OnExit, cleanup
OnMessage(DllCall("RegisterWindowMessage", Str, "TaskbarCreated"), "WM_TASKBARCREATED")
static ImmersiveShell := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}")
global IID_IVirtualDesktop, ppDesktopManager
try ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{f31574d6-b682-4cdc-bd56-1827860abec6}")
if (!ppDesktopManager)
ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{AF8DA486-95BB-4460-B3B7-6E7A6B2962B5}")
GUID(IID_IVirtualDesktop, "{FF72FFDD-BE7E-43FC-9C03-AD81681E88E4}")
ObjRelease(ImmersiveShell)
Loop 9
{
Hotkey, ^%A_Index%, switch_to_desktop
Hotkey, ^#%A_Index%, move_A_to_desktop
Hotkey, ^+%A_Index%, move_A_and_switch_to_desktop
}
return
cleanup:
if (ppDesktopManager)
ObjRelease(ppDesktopManager)
ExitApp
}
WM_TASKBARCREATED() {
Reload
}
vtable(ptr, n) {
; NumGet(ptr+0) returns the address of the object's virtual function
; table (vtable for short). The remainder of the expression retrieves
; the address of the nth function's address from the vtable.
return NumGet(NumGet(ptr+0), n*A_PtrSize)
}
GUID(ByRef GUID, sGUID) { ; Converts a string to a binary GUID
VarSetCapacity(GUID, 16, 0)
DllCall("ole32CLSIDFromString", "Str", sGUID, "Ptr", &GUID)
}
Focus() { ; Give focus to the foremost window on the desktop.
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
If IsWindowOnCurrentVirtualDesktop(this_ID)
{
WinActivate, ahk_id %this_ID%
break
}
}
}
; https://autohotkey.com/boards/viewtopic.php?p=64295#p64295
; Indicates whether the provided window is on the currently active virtual desktop.
IsWindowOnCurrentVirtualDesktop(hWnd) {
onCurrentDesktop := ""
CLSID := "{aa509086-5ca9-4c25-8f95-589d3c07b48a}"
IID := "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}"
IVirtualDesktopManager := ComObjCreate(CLSID, IID)
Error := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3*A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", hWnd, "IntP", onCurrentDesktop)
ObjRelease(IVirtualDesktopManager)
if !(Error=0)
return false, ErrorLevel := true
return onCurrentDesktop, ErrorLevel := false
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
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 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 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 at 11:08
add a comment |
up vote
2
down vote
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 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 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 at 11:08
add a comment |
up vote
2
down vote
up vote
2
down vote
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.
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.
edited Nov 18 at 11:19
answered Nov 18 at 10:41
miroxlav
6,95842363
6,95842363
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 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 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 at 11:08
add a comment |
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 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 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 at 11:08
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 at 10:49
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 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 at 11:00
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 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 at 11:08
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 at 11:08
add a comment |
up vote
0
down vote
Try this
#NoEnv
#SingleInstance Force
SetBatchLines -1
SetWorkingDir %A_ScriptDir%
main(), return
; Ctrl + number from 1 to 9
switch_to_desktop:
switchToDesktop(StrReplace(A_ThisHotkey, "^", , , 1) - 1)
Focus()
return
; Ctrl + Win + number from 1 to 9
move_A_to_desktop:
WinGet, active_id, ID, A
If !IsWindowOnCurrentVirtualDesktop(active_id)
return
IniRead, active_desktop, active_desktop.ini, active_desktop, desktop
WinHide ahk_id %active_id%
switchToDesktop(StrReplace(A_ThisHotkey, "^#", , , 1) - 1)
WinShow ahk_id %active_id%
switchToDesktop(active_desktop - 1)
return
; Ctrl + Shift + number from 1 to 9
move_A_and_switch_to_desktop:
WinGet, active_id, ID, A
If !IsWindowOnCurrentVirtualDesktop(active_id)
return
WinHide ahk_id %active_id%
switchToDesktop(StrReplace(A_ThisHotkey, "^+", , , 1) - 1)
WinShow ahk_id %active_id%
WinActivate, ahk_id %active_id%
Focus()
return
; https://autohotkey.com/boards/viewtopic.php?f=6&t=14881&hilit=Virtual+Desktop
switchToDesktop(idx) {
global ppDesktopManager, IID_IVirtualDesktop
DllCall(vtable(ppDesktopManager, 7), "Ptr", ppDesktopManager, "Ptr*", pDesktops)
if (pDesktops) {
DllCall(vtable(pDesktops, 4), "Ptr", pDesktops, "UInt", idx, "Ptr", &IID_IVirtualDesktop, "Ptr*", VirtualDesktop)
if (VirtualDesktop) {
DllCall(vtable(ppDesktopManager, 9), "Ptr", ppDesktopManager, "Ptr", VirtualDesktop)
ObjRelease(VirtualDesktop) ; I assume these should be freed
}
ObjRelease(pDesktops)
}
If (idx = "")
Index := 1
else
Index := idx +1
IniWrite, %Index%, active_desktop.ini, active_desktop, desktop
CoordMode, ToolTip, Screen
ToolTip, Desktop %Index%, (A_ScreenWidth -20), 0
}
main() {
OnExit, cleanup
OnMessage(DllCall("RegisterWindowMessage", Str, "TaskbarCreated"), "WM_TASKBARCREATED")
static ImmersiveShell := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}")
global IID_IVirtualDesktop, ppDesktopManager
try ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{f31574d6-b682-4cdc-bd56-1827860abec6}")
if (!ppDesktopManager)
ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{AF8DA486-95BB-4460-B3B7-6E7A6B2962B5}")
GUID(IID_IVirtualDesktop, "{FF72FFDD-BE7E-43FC-9C03-AD81681E88E4}")
ObjRelease(ImmersiveShell)
Loop 9
{
Hotkey, ^%A_Index%, switch_to_desktop
Hotkey, ^#%A_Index%, move_A_to_desktop
Hotkey, ^+%A_Index%, move_A_and_switch_to_desktop
}
return
cleanup:
if (ppDesktopManager)
ObjRelease(ppDesktopManager)
ExitApp
}
WM_TASKBARCREATED() {
Reload
}
vtable(ptr, n) {
; NumGet(ptr+0) returns the address of the object's virtual function
; table (vtable for short). The remainder of the expression retrieves
; the address of the nth function's address from the vtable.
return NumGet(NumGet(ptr+0), n*A_PtrSize)
}
GUID(ByRef GUID, sGUID) { ; Converts a string to a binary GUID
VarSetCapacity(GUID, 16, 0)
DllCall("ole32CLSIDFromString", "Str", sGUID, "Ptr", &GUID)
}
Focus() { ; Give focus to the foremost window on the desktop.
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
If IsWindowOnCurrentVirtualDesktop(this_ID)
{
WinActivate, ahk_id %this_ID%
break
}
}
}
; https://autohotkey.com/boards/viewtopic.php?p=64295#p64295
; Indicates whether the provided window is on the currently active virtual desktop.
IsWindowOnCurrentVirtualDesktop(hWnd) {
onCurrentDesktop := ""
CLSID := "{aa509086-5ca9-4c25-8f95-589d3c07b48a}"
IID := "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}"
IVirtualDesktopManager := ComObjCreate(CLSID, IID)
Error := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3*A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", hWnd, "IntP", onCurrentDesktop)
ObjRelease(IVirtualDesktopManager)
if !(Error=0)
return false, ErrorLevel := true
return onCurrentDesktop, ErrorLevel := false
}
add a comment |
up vote
0
down vote
Try this
#NoEnv
#SingleInstance Force
SetBatchLines -1
SetWorkingDir %A_ScriptDir%
main(), return
; Ctrl + number from 1 to 9
switch_to_desktop:
switchToDesktop(StrReplace(A_ThisHotkey, "^", , , 1) - 1)
Focus()
return
; Ctrl + Win + number from 1 to 9
move_A_to_desktop:
WinGet, active_id, ID, A
If !IsWindowOnCurrentVirtualDesktop(active_id)
return
IniRead, active_desktop, active_desktop.ini, active_desktop, desktop
WinHide ahk_id %active_id%
switchToDesktop(StrReplace(A_ThisHotkey, "^#", , , 1) - 1)
WinShow ahk_id %active_id%
switchToDesktop(active_desktop - 1)
return
; Ctrl + Shift + number from 1 to 9
move_A_and_switch_to_desktop:
WinGet, active_id, ID, A
If !IsWindowOnCurrentVirtualDesktop(active_id)
return
WinHide ahk_id %active_id%
switchToDesktop(StrReplace(A_ThisHotkey, "^+", , , 1) - 1)
WinShow ahk_id %active_id%
WinActivate, ahk_id %active_id%
Focus()
return
; https://autohotkey.com/boards/viewtopic.php?f=6&t=14881&hilit=Virtual+Desktop
switchToDesktop(idx) {
global ppDesktopManager, IID_IVirtualDesktop
DllCall(vtable(ppDesktopManager, 7), "Ptr", ppDesktopManager, "Ptr*", pDesktops)
if (pDesktops) {
DllCall(vtable(pDesktops, 4), "Ptr", pDesktops, "UInt", idx, "Ptr", &IID_IVirtualDesktop, "Ptr*", VirtualDesktop)
if (VirtualDesktop) {
DllCall(vtable(ppDesktopManager, 9), "Ptr", ppDesktopManager, "Ptr", VirtualDesktop)
ObjRelease(VirtualDesktop) ; I assume these should be freed
}
ObjRelease(pDesktops)
}
If (idx = "")
Index := 1
else
Index := idx +1
IniWrite, %Index%, active_desktop.ini, active_desktop, desktop
CoordMode, ToolTip, Screen
ToolTip, Desktop %Index%, (A_ScreenWidth -20), 0
}
main() {
OnExit, cleanup
OnMessage(DllCall("RegisterWindowMessage", Str, "TaskbarCreated"), "WM_TASKBARCREATED")
static ImmersiveShell := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}")
global IID_IVirtualDesktop, ppDesktopManager
try ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{f31574d6-b682-4cdc-bd56-1827860abec6}")
if (!ppDesktopManager)
ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{AF8DA486-95BB-4460-B3B7-6E7A6B2962B5}")
GUID(IID_IVirtualDesktop, "{FF72FFDD-BE7E-43FC-9C03-AD81681E88E4}")
ObjRelease(ImmersiveShell)
Loop 9
{
Hotkey, ^%A_Index%, switch_to_desktop
Hotkey, ^#%A_Index%, move_A_to_desktop
Hotkey, ^+%A_Index%, move_A_and_switch_to_desktop
}
return
cleanup:
if (ppDesktopManager)
ObjRelease(ppDesktopManager)
ExitApp
}
WM_TASKBARCREATED() {
Reload
}
vtable(ptr, n) {
; NumGet(ptr+0) returns the address of the object's virtual function
; table (vtable for short). The remainder of the expression retrieves
; the address of the nth function's address from the vtable.
return NumGet(NumGet(ptr+0), n*A_PtrSize)
}
GUID(ByRef GUID, sGUID) { ; Converts a string to a binary GUID
VarSetCapacity(GUID, 16, 0)
DllCall("ole32CLSIDFromString", "Str", sGUID, "Ptr", &GUID)
}
Focus() { ; Give focus to the foremost window on the desktop.
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
If IsWindowOnCurrentVirtualDesktop(this_ID)
{
WinActivate, ahk_id %this_ID%
break
}
}
}
; https://autohotkey.com/boards/viewtopic.php?p=64295#p64295
; Indicates whether the provided window is on the currently active virtual desktop.
IsWindowOnCurrentVirtualDesktop(hWnd) {
onCurrentDesktop := ""
CLSID := "{aa509086-5ca9-4c25-8f95-589d3c07b48a}"
IID := "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}"
IVirtualDesktopManager := ComObjCreate(CLSID, IID)
Error := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3*A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", hWnd, "IntP", onCurrentDesktop)
ObjRelease(IVirtualDesktopManager)
if !(Error=0)
return false, ErrorLevel := true
return onCurrentDesktop, ErrorLevel := false
}
add a comment |
up vote
0
down vote
up vote
0
down vote
Try this
#NoEnv
#SingleInstance Force
SetBatchLines -1
SetWorkingDir %A_ScriptDir%
main(), return
; Ctrl + number from 1 to 9
switch_to_desktop:
switchToDesktop(StrReplace(A_ThisHotkey, "^", , , 1) - 1)
Focus()
return
; Ctrl + Win + number from 1 to 9
move_A_to_desktop:
WinGet, active_id, ID, A
If !IsWindowOnCurrentVirtualDesktop(active_id)
return
IniRead, active_desktop, active_desktop.ini, active_desktop, desktop
WinHide ahk_id %active_id%
switchToDesktop(StrReplace(A_ThisHotkey, "^#", , , 1) - 1)
WinShow ahk_id %active_id%
switchToDesktop(active_desktop - 1)
return
; Ctrl + Shift + number from 1 to 9
move_A_and_switch_to_desktop:
WinGet, active_id, ID, A
If !IsWindowOnCurrentVirtualDesktop(active_id)
return
WinHide ahk_id %active_id%
switchToDesktop(StrReplace(A_ThisHotkey, "^+", , , 1) - 1)
WinShow ahk_id %active_id%
WinActivate, ahk_id %active_id%
Focus()
return
; https://autohotkey.com/boards/viewtopic.php?f=6&t=14881&hilit=Virtual+Desktop
switchToDesktop(idx) {
global ppDesktopManager, IID_IVirtualDesktop
DllCall(vtable(ppDesktopManager, 7), "Ptr", ppDesktopManager, "Ptr*", pDesktops)
if (pDesktops) {
DllCall(vtable(pDesktops, 4), "Ptr", pDesktops, "UInt", idx, "Ptr", &IID_IVirtualDesktop, "Ptr*", VirtualDesktop)
if (VirtualDesktop) {
DllCall(vtable(ppDesktopManager, 9), "Ptr", ppDesktopManager, "Ptr", VirtualDesktop)
ObjRelease(VirtualDesktop) ; I assume these should be freed
}
ObjRelease(pDesktops)
}
If (idx = "")
Index := 1
else
Index := idx +1
IniWrite, %Index%, active_desktop.ini, active_desktop, desktop
CoordMode, ToolTip, Screen
ToolTip, Desktop %Index%, (A_ScreenWidth -20), 0
}
main() {
OnExit, cleanup
OnMessage(DllCall("RegisterWindowMessage", Str, "TaskbarCreated"), "WM_TASKBARCREATED")
static ImmersiveShell := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}")
global IID_IVirtualDesktop, ppDesktopManager
try ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{f31574d6-b682-4cdc-bd56-1827860abec6}")
if (!ppDesktopManager)
ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{AF8DA486-95BB-4460-B3B7-6E7A6B2962B5}")
GUID(IID_IVirtualDesktop, "{FF72FFDD-BE7E-43FC-9C03-AD81681E88E4}")
ObjRelease(ImmersiveShell)
Loop 9
{
Hotkey, ^%A_Index%, switch_to_desktop
Hotkey, ^#%A_Index%, move_A_to_desktop
Hotkey, ^+%A_Index%, move_A_and_switch_to_desktop
}
return
cleanup:
if (ppDesktopManager)
ObjRelease(ppDesktopManager)
ExitApp
}
WM_TASKBARCREATED() {
Reload
}
vtable(ptr, n) {
; NumGet(ptr+0) returns the address of the object's virtual function
; table (vtable for short). The remainder of the expression retrieves
; the address of the nth function's address from the vtable.
return NumGet(NumGet(ptr+0), n*A_PtrSize)
}
GUID(ByRef GUID, sGUID) { ; Converts a string to a binary GUID
VarSetCapacity(GUID, 16, 0)
DllCall("ole32CLSIDFromString", "Str", sGUID, "Ptr", &GUID)
}
Focus() { ; Give focus to the foremost window on the desktop.
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
If IsWindowOnCurrentVirtualDesktop(this_ID)
{
WinActivate, ahk_id %this_ID%
break
}
}
}
; https://autohotkey.com/boards/viewtopic.php?p=64295#p64295
; Indicates whether the provided window is on the currently active virtual desktop.
IsWindowOnCurrentVirtualDesktop(hWnd) {
onCurrentDesktop := ""
CLSID := "{aa509086-5ca9-4c25-8f95-589d3c07b48a}"
IID := "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}"
IVirtualDesktopManager := ComObjCreate(CLSID, IID)
Error := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3*A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", hWnd, "IntP", onCurrentDesktop)
ObjRelease(IVirtualDesktopManager)
if !(Error=0)
return false, ErrorLevel := true
return onCurrentDesktop, ErrorLevel := false
}
Try this
#NoEnv
#SingleInstance Force
SetBatchLines -1
SetWorkingDir %A_ScriptDir%
main(), return
; Ctrl + number from 1 to 9
switch_to_desktop:
switchToDesktop(StrReplace(A_ThisHotkey, "^", , , 1) - 1)
Focus()
return
; Ctrl + Win + number from 1 to 9
move_A_to_desktop:
WinGet, active_id, ID, A
If !IsWindowOnCurrentVirtualDesktop(active_id)
return
IniRead, active_desktop, active_desktop.ini, active_desktop, desktop
WinHide ahk_id %active_id%
switchToDesktop(StrReplace(A_ThisHotkey, "^#", , , 1) - 1)
WinShow ahk_id %active_id%
switchToDesktop(active_desktop - 1)
return
; Ctrl + Shift + number from 1 to 9
move_A_and_switch_to_desktop:
WinGet, active_id, ID, A
If !IsWindowOnCurrentVirtualDesktop(active_id)
return
WinHide ahk_id %active_id%
switchToDesktop(StrReplace(A_ThisHotkey, "^+", , , 1) - 1)
WinShow ahk_id %active_id%
WinActivate, ahk_id %active_id%
Focus()
return
; https://autohotkey.com/boards/viewtopic.php?f=6&t=14881&hilit=Virtual+Desktop
switchToDesktop(idx) {
global ppDesktopManager, IID_IVirtualDesktop
DllCall(vtable(ppDesktopManager, 7), "Ptr", ppDesktopManager, "Ptr*", pDesktops)
if (pDesktops) {
DllCall(vtable(pDesktops, 4), "Ptr", pDesktops, "UInt", idx, "Ptr", &IID_IVirtualDesktop, "Ptr*", VirtualDesktop)
if (VirtualDesktop) {
DllCall(vtable(ppDesktopManager, 9), "Ptr", ppDesktopManager, "Ptr", VirtualDesktop)
ObjRelease(VirtualDesktop) ; I assume these should be freed
}
ObjRelease(pDesktops)
}
If (idx = "")
Index := 1
else
Index := idx +1
IniWrite, %Index%, active_desktop.ini, active_desktop, desktop
CoordMode, ToolTip, Screen
ToolTip, Desktop %Index%, (A_ScreenWidth -20), 0
}
main() {
OnExit, cleanup
OnMessage(DllCall("RegisterWindowMessage", Str, "TaskbarCreated"), "WM_TASKBARCREATED")
static ImmersiveShell := ComObjCreate("{C2F03A33-21F5-47FA-B4BB-156362A2F239}", "{00000000-0000-0000-C000-000000000046}")
global IID_IVirtualDesktop, ppDesktopManager
try ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{f31574d6-b682-4cdc-bd56-1827860abec6}")
if (!ppDesktopManager)
ppDesktopManager := ComObjQuery(ImmersiveShell, "{C5E0CDCA-7B6E-41B2-9FC4-D93975CC467B}", "{AF8DA486-95BB-4460-B3B7-6E7A6B2962B5}")
GUID(IID_IVirtualDesktop, "{FF72FFDD-BE7E-43FC-9C03-AD81681E88E4}")
ObjRelease(ImmersiveShell)
Loop 9
{
Hotkey, ^%A_Index%, switch_to_desktop
Hotkey, ^#%A_Index%, move_A_to_desktop
Hotkey, ^+%A_Index%, move_A_and_switch_to_desktop
}
return
cleanup:
if (ppDesktopManager)
ObjRelease(ppDesktopManager)
ExitApp
}
WM_TASKBARCREATED() {
Reload
}
vtable(ptr, n) {
; NumGet(ptr+0) returns the address of the object's virtual function
; table (vtable for short). The remainder of the expression retrieves
; the address of the nth function's address from the vtable.
return NumGet(NumGet(ptr+0), n*A_PtrSize)
}
GUID(ByRef GUID, sGUID) { ; Converts a string to a binary GUID
VarSetCapacity(GUID, 16, 0)
DllCall("ole32CLSIDFromString", "Str", sGUID, "Ptr", &GUID)
}
Focus() { ; Give focus to the foremost window on the desktop.
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
If IsWindowOnCurrentVirtualDesktop(this_ID)
{
WinActivate, ahk_id %this_ID%
break
}
}
}
; https://autohotkey.com/boards/viewtopic.php?p=64295#p64295
; Indicates whether the provided window is on the currently active virtual desktop.
IsWindowOnCurrentVirtualDesktop(hWnd) {
onCurrentDesktop := ""
CLSID := "{aa509086-5ca9-4c25-8f95-589d3c07b48a}"
IID := "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}"
IVirtualDesktopManager := ComObjCreate(CLSID, IID)
Error := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3*A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", hWnd, "IntP", onCurrentDesktop)
ObjRelease(IVirtualDesktopManager)
if !(Error=0)
return false, ErrorLevel := true
return onCurrentDesktop, ErrorLevel := false
}
answered yesterday
user3419297
1,636257
1,636257
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376182%2fautohotkey-winmove-virtual-desktop-of-choice%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Try github.com/sdias/win-10-virtual-desktop-enhancer
– user3419297
Nov 17 at 13:58
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 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 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 at 21:29