Advertisement
Corvust

Virtual Desktop Switching using Rainmeter and Autohotkey

Feb 28th, 2018
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Rainmeter Side of handling
  2.  
  3. [MeasureAhkWindowMessaging]
  4. Measure=Plugin
  5. Plugin=WindowMessagePlugin
  6. WindowClass=AutoHotkey
  7.  
  8. [BG]
  9. Meter=Image
  10. x=0
  11. y=0
  12. w=#SCREENAREAWIDTH#
  13. h=#SCREENAREAHEIGHT#
  14. SolidColor=0,0,0,0
  15.  
  16. [LeftSide]
  17. Meter=Image
  18. x=0
  19. y=(0.2*#SCREENAREAHEIGHT#)
  20. w=2
  21. h=(0.6*#SCREENAREAHEIGHT#)
  22. SolidColor=0,0,0,1
  23.  
  24. ;Sends a message to AHK with 'id' "10001" and 'content' "1"
  25. ;'id' and 'content' are arbitrary
  26. MouseOverAction=[!CommandMeasure MeasureAhkWindowMessaging "SendMessage 10001 1 0"]
  27.  
  28. [RightSide]
  29. Meter=Image
  30. x=(#SCREENAREAWIDTH#-2)
  31. y=(0.2*#SCREENAREAHEIGHT#)
  32. w=2
  33. h=(0.6*#SCREENAREAHEIGHT#)
  34. SolidColor=0,0,0,1
  35. ;Sends a message to AHK with 'id' "10001" and 'content' "2"
  36. ;'id' and 'content' are arbitrary
  37. MouseOverAction=[!CommandMeasure MeasureAhkWindowMessaging "SendMessage 10001 2 0"]
  38.  
  39. ;==============================================================================================
  40.  
  41. ;AutoHotkey side of Handling
  42.  
  43. #SingleInstance Force
  44. #noEnv
  45. #UseHook
  46.  
  47. SendMode Input
  48.  
  49. /*
  50. Works in conjunction with Rainmeter, VirtualDesktopSwitcher.ini
  51. Receives a message with 'id' "10001" and 'content' "1" or "2"
  52. Switches to left or right depending on the 'content'
  53.  
  54. In this case, when rainmeter sends "1", it switches to the left plane,
  55. and when rainmeter sends "2", it switches to the right plane.
  56. */
  57.  
  58. OnMessage(10001, "RainmeterWindowMessage")
  59. RainmeterWindowMessage(wParam, lParam) {
  60.   If (wParam = 1) {
  61.     Send #^{Left}
  62.   }
  63.   If (wParam = 2) {
  64.     Send #^{Right}
  65.   }
  66.   Sleep 300
  67. }
  68.  
  69. /*
  70. Binds "windows+w" to close the current virtual desktop,
  71. and binds "windows+n" to open a new virtual desktop.
  72. */
  73.  
  74. #w::send, #^{F4}
  75. #n::send, #^d
  76.  
  77. ;==============================================================================================
  78.  
  79. ;Copy the rainmeter section of code and save as .ini
  80. ;Copy the AutoHotkey section of code and save as .ahk
  81. ;Load the .ini file and run the .ahk file
  82. ;Reference: https://autohotkey.com/boards/viewtopic.php?t=12476
  83.  
  84. ;Edited Autohotkey's section for optimisation, replaced chunky code with one liner that works better.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement