Skip to content

Instantly share code, notes, and snippets.

@jasondavis
Forked from G33kDude/EasyStreamDeck.ahk
Created April 16, 2023 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasondavis/01df88280e5852e7690dc06ab9ae3bb6 to your computer and use it in GitHub Desktop.
Save jasondavis/01df88280e5852e7690dc06ab9ae3bb6 to your computer and use it in GitHub Desktop.
Launch AutoHotkey code from a StreamDeck efficiently using GET requests
#NoEnv
#Persistent
SetBatchLines, -1
#Include <Socket>
/*
Launch AutoHotkey code from a StreamDeck efficiently using GET requests
Step 1: Copy this template
Step 2: Write some functions under the "User Functions" heading (no parameters)
Step 3: Add the "System > Website" button to your StreamDeck
Step 4: Fill in the "URL" as "http://localhost:1337/YourFunctionName"
Step 5: Check the "GET request in background" button
Step 6: While the script is running, test the button on your StreamDeck
*/
Server := new SocketTCP()
Server.OnAccept := Func("OnAccept")
Server.Bind(["127.0.0.1", 1337])
Server.Listen()
return
; --- Server Code ---
OnAccept(server)
{
sock := server.Accept()
request := StrSplit(sock.RecvLine(), " ")
if (request[1] != "GET")
{
sock.SendText("HTTP/1.0 501 Not Implemented`r`n`r`n")
sock.Disconnect()
return
}
fname := LTrim(request[2], "/")
if IsFunc(fname)
{
SetTimer, % fname, -0
sock.SendText("HTTP/1.0 200 OK`r`n`r`n")
sock.Disconnect()
return
}
sock.SendText("HTTP/1.0 404 Not Found`r`n`r`n")
sock.Disconnect()
return
}
; --- User Functions ---
Example()
{
MsgBox, Example
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment