Does AHK handle win-10/11(+) built-in virtual desktops for moving windows?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
thenomad
Posts: 48
Joined: 13 Jun 2016, 14:56

Does AHK handle win-10/11(+) built-in virtual desktops for moving windows?

Post by thenomad » 04 Oct 2022, 16:28

Please assume this scenario:

I have 2 virtual desktops on win 10
On my first virtual desktop I have a google chrome window open for which I have the exact "wintitle" (assume "XYZ - Google Chrome")
On my second virtual desktop I have a notepad open, again I know the exact wintitle for it.(assume "Notepad mytext"

And assume I ran this script

Code: Select all

winactivate, XYZ - Google Chrome
sleep 500 ; for good measure
mousemove 200,200 ;soemwhere in the chrome window
sleep 200
mouseclick, L
sleep 100
send ^a
sleep 100
send ^c

winactivate, Notepad mytext
sleep 500
mousemove 200,200
sleep 200
mouseclick, L
sleep 100
send ^v
[Mod edit: [code][/code] tags added.]

I think the purpose of the script is pretty clear. Will this try to switch between two virtual desktops every time it runs into winactivate or will it give some sort of error or do nothing because the other window referenced is not found ?

More important question is, how do you handle switching among several virtual desktops other than simulating mouse clicks on the toolbar virtual desktops icon?
Last edited by gregster on 04 Oct 2022, 16:58, edited 1 time in total.
Reason: Please use code tags. Thank you!

User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Does AHK handle win-10/11(+) built-in virtual desktops for moving windows?

Post by mikeyww » 04 Oct 2022, 17:45

Hello,

The answer to, "What happens if I run my script?" seems to be to run your script.

I believe that virtual keyboards can also be changed with a keyboard sequence, which you can readily send via AHK if needed. There is no need to click.

User avatar
thenomad
Posts: 48
Joined: 13 Jun 2016, 14:56

Re: Does AHK handle win-10/11(+) built-in virtual desktops for moving windows?

Post by thenomad » 05 Oct 2022, 17:45

Thank you for your suggestion of "trying" but my matter is not as simple as this. And with what I have in mind, testing every possible scenario is not something I want to do. This is why I am here, asking expert opinions or at least from those who dealt with virtual desktops on AHK before.

I use virtual desktops very heavily, as my work requires compartmentalization. Depending on which physical machine I am on, there is 3 to 7 different virtual desktops with several different application windows open on each of them.

The purpose of this experiment is, locating what is on which virtual desktop, so that I can make a note to myself (automatically if this works one day) so that if the machine takes a nose dive, I may have a chance to rebuild the windows configuration after the power up.

To start, the prudent thing is, knowing how many virtual desktops do I have. Imitating ctrl-win-cursor-L/R and counting is counter intuitive as two empty desktops will look the same. Hence my quest. How does AHK manage/address vistual desktops, if any ?

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Does AHK handle win-10/11(+) built-in virtual desktops for moving windows?

Post by malcev » 05 Oct 2022, 18:33

Each virtual desktop has its own guid.
There is unofficial api to work with them.
But every version of windows has different iid, methods calling and functionality.
You can start to learn from here
viewtopic.php?t=67642

GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Does AHK handle win-10/11(+) built-in virtual desktops for moving windows?

Post by GEV » 06 Oct 2022, 01:15

This works on my system

Code: Select all

F1::
	SetTitleMatchMode, 2
	DetectHiddenWindows, On
	WinActivate, Ask For Help - AutoHotkey Community - Google Chrome
	WinWaitActive, Ask For Help - AutoHotkey Community – Google Chrome, ,2
	if (ErrorLevel)
	{
		MsgBox Chrome not active
		return
	}
	mousemove 200,200 ;soemwhere in the chrome window
	sleep 200
	send ^a
	sleep 100
	send ^c
	WinActivate, Notepad mytext
	WinWaitActive, Notepad mytext, ,2
	if (ErrorLevel)
	{
		MsgBox Notepad not active
		return
	}
	sleep 100
	send ^v
return
thenomad wrote:
04 Oct 2022, 16:28
how do you handle switching among several virtual desktops other than simulating mouse clicks on the toolbar virtual desktops icon?
Try https://github.com/FuPeiJiang/VD.ahk

Post Reply

Return to “Ask for Help (v1)”