pmb6tz / windows-desktop-switcher Goto Github PK
View Code? Open in Web Editor NEWAn AutoHotKey script for Windows that lets a user change virtual desktops by pressing CapsLock + <num>.
License: MIT License
An AutoHotKey script for Windows that lets a user change virtual desktops by pressing CapsLock + <num>.
License: MIT License
This is very useful for me ,thanks author!
I use strokens plus work with this ahk script,which can make mouse move to control the virtual desktop switch. left right top button of mouse move to switch four virtual desktops. which is really wonderful.
but ,I have a new idea that pin a application on the top of any virtual desktop nomatter I switch it.
whether can make it ?
I don't like to create desktops on demand, so I would like the script to create 9 empty desktops when it's launched.
I've achieved this with the following code:
createInitialDesktops()
{
global DesktopCount, CurrentDesktop, NumInitialDesktops
OutputDebug, Creating %NumInitialDesktops% initial desktops
Current := CurrentDesktop
Loop, % NumInitialDesktops - DesktopCount
{
createVirtualDesktop()
}
OutputDebug, Switching back to desktop %Current%
_switchDesktopToTarget(Current)
}
The problem with this solution is that NumInitialDesktops
must be hard-coded inside the main script, and can't be imported from user_config.ahk
. A potential solution could be to introduce a new script user_variables.ahk
. (And rename user_config.ahk
to user_hotkeys.ahk
?)
Hi. Tell me please, how i can disable auto-cycles from the first to the last desktop?
I've implemented this in my own private fork, but don't use it much, so I won't submit a PR. Regardless, I thought that someone might like to see this implemented? Function is already present in the dll, so this could be added with just a few lines of code.
Although it's probably not essential, so I won't submit a PR just yet, to avoid feature creep :)
Thanks a lot for your great tool that has been a lifesaver so far!
I was using a similar software that is no longer maintained.
Is there any way to disable the "Ctrl + Alt" feature described below?
Using Ctrl + Alt instead of CapsLock also works, without any additional changes necessary (e.g. use + + 1 to switch to the Desktop 1, just as you would use + 1)
It keeps working even when disabling the CapsLock shortcut on the user_config.ahk file !
Many symbols require the "Alt Gr" (@, #, {) on FR keyboards.
Moreover "Ctrl + Alt" is equivalent to "Alt Gr" on such keyboards.
Therefore this default behavior is interfering a lot with my typing!
Is there any way to disable it?
You will see what I mean by referring to the AZERTY layout.
Many thanks!
I often have to open Win + Tab
to organize my desktops, although I feel it interrupts my flow, especially when I have to open it for moving just one window.
The easy way to implement this would be to use the dll that is already present by calling this function from it: MoveCurrentWindowToDesktop(number)
(source here)
@pmb6tz, would you approve such PR? I'd also suggest these hotkeys with the PR: switching to desktop 1 with Tab + 1
, moving active window to desktop 1 with CapsLock + 1
EDIT: I've already implemented this in my own private fork, works flawlessly
Hello,
I am trying to use this code on my surface go, but it doesn't allow me to shift to another desktop. I have installed the addons as mentioned here.
I was able to get around this issue using AHK codes. A sample is as per below:
`
KeyWait, CapsLock
Send, {LCtrl down}{LWin down}
Loop 10
{
Send, {Left}
Sleep, 100
}
Sleep, 25
Loop 8 ;Desktop 9
{
Send, {Right down}{Right up}
Sleep, 200
}
Send, {LWin up}{LCtrl up}
`
When I remap the bottom section with LWin
, the hotkeys work properly:
; User config!
; This section binds the key combo to the switch/create/delete actions
LWin & 1::switchDesktopByNumber(1)
LWin & 2::switchDesktopByNumber(2)
LWin & 3::switchDesktopByNumber(3)
LWin & 4::switchDesktopByNumber(4)
LWin & 5::switchDesktopByNumber(5)
LWin & 6::switchDesktopByNumber(6)
LWin & 7::switchDesktopByNumber(7)
LWin & 8::switchDesktopByNumber(8)
LWin & 9::switchDesktopByNumber(9)
LWin & c::createVirtualDesktop()
When I remap the bottom section with RWin
, the hotkeys do not work properly:
; User config!
; This section binds the key combo to the switch/create/delete actions
LWin & 1::switchDesktopByNumber(1)
LWin & 2::switchDesktopByNumber(2)
LWin & 3::switchDesktopByNumber(3)
LWin & 4::switchDesktopByNumber(4)
LWin & 5::switchDesktopByNumber(5)
LWin & 6::switchDesktopByNumber(6)
LWin & 7::switchDesktopByNumber(7)
LWin & 8::switchDesktopByNumber(8)
LWin & 9::switchDesktopByNumber(9)
LWin & c::createVirtualDesktop()
I created a test script to verify that LWin
and RWin
are working properly in other scripts and it behaves as expected:
LWin & 1::Send, testing lwin & 1
RWin & 1::Send, testing rwin & 1
Any ideas or insight?
Hi, I have a question. I am switching between desktops with <!1::switchDesktopByNumber(1)
and <!2::switchDesktopByNumber(2)
In dekstop 1 I am using a txt editor, in desktop 2 something else. When I switch from desktop 1 to 2 and then back to 1 I can't continue writing till I click on the txt editor. All windows are out of focus when returning to the desktop. This doesen't happen when I slide with 4 fingers on the trackpad to switch between the desktops. Can you help me out please?
Thank you
Surfacing a comment from issue #11 which I think should be considered as a feature.
How do I tell Windows (or the active program) to pin its window or all its app's windows to all desktops?
In another virtual desktop manager, I found an AutoHotKey line that looks something like
PostMessage, % WM_SYSCOMMAND , % desktopnumber, % windowid, , % "ahk_id " windowid
(exact line is line 82 of https://github.com/jpginc/windows10DesktopManager/blob/master/dllWindowMover.ahk )
To the best of my understanding, what this is doing is telling that window that it is now on the other desktop.
I have no idea how to derive this command, and I am also wondering how also to derive a command that would tell the window (or the windows shell, if that is the case) to pin the app (or just the current window) to all Virtual Desktops.
The main reason I am even writing these codes is because I want these features myself and they are not implemented yet >_<
Thank you all for sharing and I will look into this.
Originally posted by @ghost in #11 (comment)
Hey!
I'm usually not using this platform so I don't know if this is the right place for feature request. Sorry if it's not!
Could you implement a hotkey for placing a window on another desktop? Like pressing Ctrl+Alt+ and the window will be transferred to the specified desktop.
That would make your already great tool near perfect. Thanks for making this either way!
Title explains it.
Windows 10
64-bit
For some reason whenever I have the script running the button '3' is not working.
The button on the num pad is working but the other one is not. Is this a bug?
Hi!
First off: thanks! Your script is great. But I figure something is still not quite in place as sometimes (but lately more often) capslock actually stays locked after using it.
Is there someway to heal this issue?
Using ALT does not really pose as an alternative as it is not a as convenient hotkey.
I appreciate any help!
Thanks
When reading the docs about the dll that is used here, I've noticed that there is one helper function that should probably be in this repo too. But I haven't noticed any bugs myself that would require this, though, so I won't submit a PR just yet.
RestartVirtualDesktopAccessorProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "RestartVirtualDesktopAccessor", "Ptr")
; Restart the virtual desktop accessor when Explorer.exe crashes, or restarts (e.g. when coming from fullscreen game)
explorerRestartMsg := DllCall("user32\RegisterWindowMessage", "Str", "TaskbarCreated")
OnMessage(explorerRestartMsg, "OnExplorerRestart")
OnExplorerRestart(wParam, lParam, msg, hwnd) {
global RestartVirtualDesktopAccessorProc
DllCall(RestartVirtualDesktopAccessorProc, UInt, result)
}
There are other useful functions such as a Hook that will execute right after a desktop switch event, even when desktop is not switched with the script. Also there are functions GoToDesktopNumber
, GetCurrentDesktopNumber
, etc that may or may not work better than the current ones.
There is a time to time scenario where I have to move back and forth the virtual desktop to see the contents.
And it really bugged me that I had to keep release & push modifier keys(ctrl, alt, shift etc...) again to send the command.
Put below commands into the user_config.ahk
to hold down the modifier keys after command.
(If you are still pressing them, of course)
#HotkeyModifierTimeout -1
This way you can jump desktop back & forth just by pressing 1 & 2 while hold down the modifier key.
By the way, thank you for great script. It really helped me moving back to windows from mac.
more info : https://www.autohotkey.com/docs/commands/_HotkeyModifierTimeout.htm
I often touch CapsLock by mistake, so it switch to Capital, I want use CapsLock for switcher only, so how to disable CapsLock original function?
I've noticed that, at the leftmost desktop, if you press the command for moving to the desktop to the left an odd number of times, the next command to shift to the desktop to the right does not do anything (but then the next command to move right works correctly). If you press the command for moving to the desktop to the left an even number of times (when you are at the leftmost desktop), the script works fine. I haven't tried it for the opposite situation (when you are one the right most desktop moving right), but I imagine it is the same case there.
I have no idea why this is happening for ctrl+alt+num; instead it seems to send win+right or win+left. I am using Windows 10 on a ThinkPad X220.
This messes my AltGr key. I'm using Nordic (Finnish) keyboard layout. It gives AltGr the same function as to Capslock
Hi,
Are you planning to release the source code of virtual-desktop-accessor.dll
? I would like to inspect its workings. Also, headers would be helpful.
Thank you.
Great job with this project! I don't think any of us could bear using Windows VD if there we couldn't use keyboard shortcuts.
I was wondering... in the past when I was a Mac user, I used an application called TotalSpaces2 on the Mac (https://totalspaces.binaryage.com/). It's a VD manager for the Mac but what I really like about it is that you can set up a your desktops in a 2D grid (22, 33...) and you can use the arrow keys to quickly navigate between them. I liked it much more than the single row in Windows VD. The main benefit being you can more quickly navigate between desktops (less key presses) and you can set your programs up in a simple pattern that's easy to remember and navigate (I find navigation more challenging in the linear system due to the need to cycle left and right repeatedly or to remember the number of all your desktops).
I have very little experience with AHK (and any type of programming) but I was trying to mod another script simply by inputting each and every direction the system would have to navigate if left, right, up or down was pressed on a 3 by 3 grid. I was also trying to set it up so that if left was pressed on desktop 1 in a 3*3 grid then the navigation would wrap around to desktop 3. Similarly hitting up on desktop1 would wrap around to desktop 7. Not sure how hard or easy this would be to implement but if this is a feature you could add then I would be forever grateful (probably some other users would appreciate this feature too). :)
Is there support for changing the wallpaper for each individual desktop? There was another .AHK script out there that used to do this, but no longer works =(
Originally posted by @kalamalka in #57 (comment)
I was looking for a command to get the current virtual desktop ID, because I wanted to use wallpapers for different virtual desktops. The functions in your code worked well and saved me hours of putting together some API DLL or figuring out how to extract the ID from the registry.
Here's the (mostly) finished result:
https://github.com/noido/ahk-change_windows_virtualDestop_background
Enjoy :)
Thank you so much for this script. This has been the one thing that has been bothering me with the Windows virtual desktops, and now they are finally workable.
I don't know if you do feature requests, but just in case: Would it be possible to show the number of the current virtual desktop on the system tray icon? That way I always know what desktop I'm on.
Except for pop notification for pin or unpin operation, switch backgroud with desktop can make switch more clear .
AutoAssociateBackgroundWithDesktop := false
BackgroundPicPaths := ["C:\Users\A\Pictures\VDPic\day.jpg", "C:\Users\A\Pictures\VDPic\snow.jpg", "C:\Users\A\Pictures\VDPic\sex.jpg", "C:\Users\A\Pictures\VDPic\cool.jpg"]
……
changeBackgroundWithDesktopId()
{
global CurrentDesktop, BackgroundPicPaths, AutoAssociateBackgroundWithDesktop
filePath := BackgroundPicPaths[CurrentDesktop]
if (AutoAssociateBackgroundWithDesktop and filePath and FileExist(filePath)) {
DllCall("SystemParametersInfo", UInt, 0x14, UInt, 0, Str, filePath, UInt, 1)
}
}
_Originally posted by @fanlushuai in https://github.com/pmb6tz/windows-desktop-switcher/issues/55#issuecomment-629744607_
Anny way to make the desktop not also switch when moving an app to another desktop?
default key is win+tab.
I'd like to customize it.
Hey!
First, love the script and everything about it! Thanks for putting time and effort into creating it. Hopefully you will continue to update it as i now have adapted it fully into my everyday use and it's awesome!
I Just have one suggestion, and please forgive me if this is the wrong place to submit this, not really too common with GitHub.
Anyway, the Caps Lock key is perfect for the usage of this script, love it. The only thing is, i never use the "regular" function of the standard Caps Lock key as i only use Shift when needed. So, sometimes when switching desktops i end up with the Caps Lock function turned on resulting in capital letters.
Is there any way to configure Caps Lock to only toggle desktops and not the "regular" function?
Keep up the great work!
(Tried to label this as an suggestion or enhancement but couldn't find out how.)
In autohotkey we usually have the ability to use left and right arrow keys. In the user config I have tried:
^{Right}::switchDesktopToRight()
^{Left}::switchDesktopToLeft()
but getting error that these keys are not valid.
I can not use caps + azerty to move active windows to another destop.
It simply behaves the same as pressing caps + 1234.
Thanks for this amazing script, much appreciated.
I would however love to see a feature where you cycle through all the windows with just one hotkey, for example windows key + tab (although that example, specifically, is used for that stupid virtual desktop overview that Microsoft added).
So if you have lets say three virtual desktops, when you are cycling through them with the new hotkey, when reaching the last desktop, if you were to click the cycle button again you would go back to the first desktop.
Thanks again!
Edit: I made my own solution, but I see that you already created a pull request. Although I don't need it now, I think others might find it useful.
Hi @pmb6tz
This is such a useful script, thank you for building it! I've been working remotely now for a few weeks and this script has been a saviour when only having one screen.
I'm trying to get the MoveCurrentWindowToDesktop(desktopNumber) to work, but haven't had any success.
The program stays on the original desktop. So the issue must be this line:
DllCall(MoveWindowToDesktopNumberProc, UInt, activeHwnd, UInt, desktopNumber - 1)
Which looks at:
global MoveWindowToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "MoveWindowToDesktopNumber", "Ptr")
I haven't done any dll call stuff yet, so unsure where the issue may lay or if I missing something. Please let me know what I should look at to get this working. Thanks.
Regards,
submeg
It would be great if there was an option to remember the active window before switching at every desktop, so it would be focused once switched back.
I assume a simple alt+tab won't work, since it produces unexpected behaviour at rapid switching. You would probably need to store some window UUIDs, assuming that's doable.
So the WinActivate after switching a desktop is not working for me, on update 1809 and 1903.
As a workaround, I put the line "Send, {ALT DOWN}{TAB}{ALT UP}" just before the line "focusTheForemostWindow(targetDesktop)" (which can be commented out). The line simulates pressing Alt+Tab shortly, which just focusses the top most window.
I don't know what causes the problem, and if anyone else is also having it, but I think it comes down to getForemostWindowIdOnDesktop(n) not returning a windowID.
First of all, thank you for great piece of work!
However, I am often using 10+ task views (crazy, right?) and switching between them becomes a bit nauseating experience (especially going from 1 to 10). Is there any way to just go "straight" to the desktop without going through all of the other ones?
As the title says the shortcuts don't work when the task manager is open and the window is selected. Is this the restriction of windows? Can something be done about it?
Windows 10 1909.
EDIT: my bad, misread the docs
If you sign out and then sing in again, there won't be reg key at ...\SessionInfo\1\...
, it will be ...\SessionInfo\2\...
.
Hello, is it possible to use the Win key as the modified for switching the desktops?
Thank you!
Just ad the powershellscript to the install location.
I've noticed that if a command prompt (cmd) window is currently focused, it captures the caps+num sequence, preventing desktop switching entirely. I personally use command windows quite a lot, so I'm adding an item to take a look at this issue.
I think it would be great to try and create a debugger tool which would test various parts of this script and/or allow to automatically/manually choose desktop switching methods, hmm. It might help to provide quickfixes or better bug reports for script users.
This could provide clues to help fix all of our currently open issues (#59 #46 #54)
After updating windows 10 to 11 (built 22000.51) this function is no longer working. Compiling with autohotkey -v 1.1.39 unicode 64 bit. any suggestions how to make it work again?
Thank you very much!
I'm using the default key binding: CapsLock & tab::switchDesktopToLastOpened()
.
Steps to reproduce:
CapsLock & 2::switchDesktopByNumber(2)
CapsLock & 1::switchDesktopByNumber(1)
switchDesktopToLastOpened()
Now it's not hard to see what's happening here, the variable LastOpenedDesktop
is only set in _switchDesktopToTarget
(LastOpenedDesktop := CurrentDesktop
). Because of this, any other way of moving to another desktop will not register into the variable LastOpenedDesktop
, thus leaving value 2
in LastOpenedDesktop
, even though I'm currently at desktop 2 and 1 was my previous desktop.
tl;dr: this program assumes it is in complete control over switching desktops, leading to broken functionality
I've thought about this for a while, but I haven't been able to come up with a clean solution.
My setup has 4 virtual desktops, and I noticed that often times when switching from first to fourth desktop, some windows from second or third or even both appear flashing on fourth desktop. I guess that's because to get to it I have to cycle through each desktop in between.
I've managed to fix that[1] by choosing target desktop on Task View and only then switching to it. It goes like this:
On the downside you can see a bit of Task View opening animation, but the wait is unnoticeable.
If you encountered this problem before and you're OK with the solution, I'd be grateful to create a PR.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.