Has anyone wrote a hotkey for Slack to close/leave?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
geekyadam
Posts: 45
Joined: 01 Aug 2016, 17:11

Has anyone wrote a hotkey for Slack to close/leave?

20 Aug 2021, 12:43

Slack has many keyboard shortcuts, however closing or leaving a conversation is not one of them. Within Slack, it can be accomplished in one of three ways from what I can tell:
1. Right-click conversation in left sidebar, choose "Close conversation"
2. Click the little "x" on the right side of a conversation (also in the left sidebar)
3. Use the "/leave" command within a channel or DM (it is relevant to note that doing so in a channel results in a popup asking for confirmation, whereas leaving a DM chat does not ask confirmation, it just closes it)

Obviously the third option seems like best route for a hotkey. So I created a simple one, but I found that Slack doesn't accept the input that fast so I added some sleeps to accommodate:

Code: Select all

^w::
	Send /
	Sleep 200
	Send leave{ENTER}
	Sleep 200
	Send {ENTER}
return
This is not a great solution, as it sends a closing Enter keystroke even when in a DM chat. I don't think it causes any issues within Slack (just pressing enter out of no where doesn't do anything without text in the input field), so it's acceptable for now. I'm also just not a fan of using Sleeps unless absolutely necessary. Which is why I'm posting here.

Does anyone have a more elegant, more precise, or more reliable hotkey for closing a Slack conversation?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Has anyone wrote a hotkey for Slack to close/leave?

20 Aug 2021, 13:15

Try:

Code: Select all

SetKeyDelay, 200, 50

^w::Send, /leave{ENTER 2}
User avatar
geekyadam
Posts: 45
Joined: 01 Aug 2016, 17:11

Re: Has anyone wrote a hotkey for Slack to close/leave?

23 Aug 2021, 10:20

Xtra wrote:
20 Aug 2021, 13:15
Try:

Code: Select all

SetKeyDelay, 200, 50

^w::Send, /leave{ENTER 2}
Thanks for that, I could just use setkeydelay rather than adding individual sleeps. Please remind me...what would the command be to reset SetKeyDelay back to defaults afterward? Looking at docs, there isn't just a default parameter, so I think I'd need to do a setkeydelay command with explicit values to match the default ones. Is that accurate? Or is there a simpler wait to reset the delays?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Has anyone wrote a hotkey for Slack to close/leave?

23 Aug 2021, 10:41

The defaults for SendEvent mode is:

Code: Select all

SetKeyDelay, 10, -1
That should work give it a try

If you have multiple hotkeys you can test this example and see its per thread (hotkeys create a new thread)

Code: Select all

;~ SetKeyDelay, 10, -1    ; default setting in autoexec section (top of the script)


$n::Send, This is a test of autoexec setting    ; (aka default setting)

$m::
    SetKeyDelay, 200, 50
    Send, This is a test of this hotkey thread setting
return
User avatar
geekyadam
Posts: 45
Joined: 01 Aug 2016, 17:11

Re: Has anyone wrote a hotkey for Slack to close/leave?

23 Aug 2021, 15:58

Xtra wrote:
23 Aug 2021, 10:41
The defaults for SendEvent mode is:

Code: Select all

SetKeyDelay, 10, -1
That should work give it a try

If you have multiple hotkeys you can test this example and see its per thread (hotkeys create a new thread)

Code: Select all

;~ SetKeyDelay, 10, -1    ; default setting in autoexec section (top of the script)


$n::Send, This is a test of autoexec setting    ; (aka default setting)

$m::
    SetKeyDelay, 200, 50
    Send, This is a test of this hotkey thread setting
return
Oh, so in this example, would the third Send command be using the defaults or the 200, 50 settings?

Code: Select all

$n::Send This should use the default settings.
$m::
	SetKeyDelay 200, 50
	Send This should use the 200, 50 settings.
return
$a::Send What settings would this use?
Would the third Send command use the defaults because the SetKeyDelay will only apply to the second Send command's thread? Or would I need to do a SetKeyDelay 10, -1 before the third Send command for it to use default settings?
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Has anyone wrote a hotkey for Slack to close/leave?

23 Aug 2021, 18:42

Code: Select all

Oh, so in this example, would the third Send command be using the defaults or the 200, 50 settings?
It would be the default settings. (you can test it in notepad to check the differences)

HTH
User avatar
geekyadam
Posts: 45
Joined: 01 Aug 2016, 17:11

Re: Has anyone wrote a hotkey for Slack to close/leave?

24 Aug 2021, 10:43

Just FYI for anyone else going the same route, SendMode Input doesn't support SetKeyDelay, so you have to either set SendMode to something other than Input up in auto-exec section, or just use SendEvent or SendPlay within the hotkey. For example, here's my hotkey to leave a channel in Slack:

Code: Select all

^w::
	SetKeyDelay 50
	SendEvent /leave{ENTER}
	/*
	Send /
	Sleep 200
	Send leave
	Sleep 200
	Send {ENTER}
	*/
return
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Has anyone wrote a hotkey for Slack to close/leave?

24 Aug 2021, 13:53

If sendmode is not specified in auto-exec section the default is SendEvent.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: apeironn, Bing [Bot], Descolada, fiaztv1, Google [Bot], JKJadan, Pianist and 215 guests