How to create hotkeys for switching windows to specific desktops in Windows 10 using AutoHotKey

1

So, I have created an AutoHotKey script to easily switch to 9 different desktops using the number pad (think of it like a 3x3 grid, sort of). The problem is I also want to have hotkeys to move windows to another desktop, and the menu selections always omit the current desktop (see the last hotkey in the sample code). So far I have it do Win-Tab, then the AppsKey, then M, which brings up the menu to move the current window somewhere. At this point, if all desktops were listed, I could just move down by some count. However, the current desktop is always omitted, making this impossible--I can get off by one errors.

What I have right now is passable (a single key that brings up the menu, and leaves the rest to me), but I would like to go further without having to write a ton of code.

Since I can't know quite which menu item to choose, I can't finish this. Is there an easy way to manage this problem? For example, maybe there is a way to move down by N items, then check what the current menu item text is, and adjust by 1?

Here's my sample code. It's only the last hotkey in the list that really matters, but the rest are there to illustrate my setup so far.

The salient question is this: How can I have a unique hotkey like Win-Shift-Numpad3 to move the current window to desktop 3, but have unique hotkeys from 1 through 9?

; Windows+Number pad keys = Windows 10 desktop switching.
; number pad to match a 3x3 desktop
#Numpad1::
#NumpadEnd::
    Send, {LWin down}{Ctrl down}{Right 9}{Left 2}{Ctrl up}{LWin up}
    return
#Numpad2::
#NumpadDown::
    Send, {LWin down}{Ctrl down}{Right 9}{Left 1}{Ctrl up}{LWin up}
    return
#Numpad3::
#NumpadPgDn::
    Send, {LWin down}{Ctrl down}{Right 9}{Ctrl up}{LWin up}
    return
#Numpad4::
#NumpadLeft::
    Send, {LWin down}{Ctrl down}{Left 9}{Right 3}{Ctrl up}{LWin up}
    return
#Numpad5::
#NumpadClear::
    Send, {LWin down}{Ctrl down}{Left 9}{Right 4}{Ctrl up}{LWin up}
    return
#Numpad6::
#NumpadRight::
    Send, {LWin down}{Ctrl down}{Right 9}{Left 3}{Ctrl up}{LWin up}
    return
#Numpad7::
#NumpadHome::
    Send, {LWin down}{Ctrl down}{Left 9}{Ctrl up}{LWin up}
    return
#Numpad8::
#NumpadUp::
    Send, {LWin down}{Ctrl down}{Left 9}{Right 1}{Ctrl up}{LWin up}
    return
#Numpad9::
#NumpadPgUp::
    Send, {LWin down}{Ctrl down}{Left 9}{Right 2}{Ctrl up}{LWin up}
    return

;   Bring up the "move this window to desktop..." menu.  Since the menu is always different, don't operate on it.  Just leave it at that.
#!Numpad0::
#!NumpadIns::
#+Numpad0::
#+NumpadIns::
#Numpad0::
#NumpadIns::
    Send, {LWin down}{Tab}{LWin up}
    Sleep, 400
    Send, {AppsKey}M
return

K Robinson

Posted 2016-11-04T19:51:20.740

Reputation: 897

@user3419297 what does it do? Just posting a link to a script doesn't help if there's no context available. – LPChip – 2016-11-04T21:56:41.870

I have tried the windows desktop manager a few times, but I find it too limited for what I want, so I went for Dexpot, which has all the functions you're trying to build now. In fact, it even offers a rules section which will automatically move windows to predefined desktops on the fly, offering the ability to automatically switch to that desktop if you want. – LPChip – 2016-11-04T21:58:21.420

@LPChip, the dexpot website appears to show they don't have great support for windows 10. I was using VirtuaWin (happily), which has a lot of advanced features but can still be a bit clunky. I don't really want to pay $27 USD (this is for my work PC) when I can just go back to VirtuaWin. Still, thanks for the pointer. I hope others besides me find it useful! – K Robinson – 2016-11-07T17:23:17.700

@KRobinson I am using DexPot on windows 10 without much problems. – LPChip – 2016-11-07T18:47:18.467

No answers