rt3x.de NoPaste

MoveWindowBetweenDesktops.ahk

This is a nopaste service, powered by Flying Paste.

Author: Malte Bublitz
Language/File type: AutoHotKey Script

Description

Move a window between desktops using a keyboard shortcut.

Does not work for all Windows, especially those without the classic window title bar.

NOTE: tango_executable.ico was generated from https://xyz.rolltreppe3.de/img/icons_tango/executable-512.png

Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;@Ahk2Exe-SetName          MoveWindowBetweenDesktops
;@Ahk2Exe-SetDescription   "Move Window between desktops (Keyboard Shortcut)"
;@Ahk2Exe-SetCopyright     "Copyright © 2021 Malte Bublitz"
;@Ahk2Exe-SetCompanyName   rolltreppe3
;@Ahk2Exe-SetMainIcon      tango_executable.ico
;@Ahk2Exe-SetOrigFilename  MoveWindowBetweenDesktops.ahk

;
; https://superuser.com/a/1538134
;
; Modified to <Ctrl><Shift><Super><Left> resp. <Ctrl><Shift><Super><Right> to be
; more like the usual X11 shortcut, and to avoid conflicts with Window Snapping
;
^+#Left::
  WinGetTitle, Title, A
  WinSet, ExStyle, ^0x80, %Title%
  Send {LWin down}{Ctrl down}{Left}{Ctrl up}{LWin up}
  sleep, 50
  WinSet, ExStyle, ^0x80, %Title%
  WinActivate, %Title%
Return

^+#Right::
  WinGetTitle, Title, A
  WinSet, ExStyle, ^0x80, %Title%
  Send {LWin down}{Ctrl down}{Right}{Ctrl up}{LWin up}
  sleep, 50
  WinSet, ExStyle, ^0x80, %Title%
  WinActivate, %Title%
Return