Improve desktop switching script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
aappletart
Posts: 2
Joined: 12 Dec 2017, 01:55

Improve desktop switching script?

12 Dec 2017, 02:20

Hi, I'm a noobie at using ahk (and programming in general) and I wanted to write a script that switches to a specific desktop. For example, Capslock+3 switches to desktop 3. I wrote this script but as you can see or if you try it out, it's not very robust. Can anyone give any tips on how to improve it? Thanks! :D

Code: Select all

SetCapsLockState, AlwaysOff
desktop = 1

Switch(d)
{
	global
	
	press := (d-desktop)
	desktop = %d%

	If press < 0
		direction = Left
	else if press > 0
		direction = Right
	else
		return
		
	press := Abs(press)
	
	Loop, %press%
	{
		SendInput, ^#{%direction%}
		Sleep, 75
	}
	
	return
}

CapsLock & 1::
	Switch(1)
return

CapsLock & 2::
	Switch(2)
return

CapsLock & 3::
	Switch(3)
return

CapsLock & 4::
	Switch(4)
return

^#Left::
	SendInput ^#{Left}
	If desktop > 1
		desktop--
return
	
^#Right::
	SendInput ^#{Right}
	If desktop < 4
		desktop++
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mikeyww and 382 guests