Skip to content

Instantly share code, notes, and snippets.

@G33kDude
Created March 12, 2022 19:20
Show Gist options
  • Save G33kDude/c94ce4a847ac59913ccf52b0a3075f61 to your computer and use it in GitHub Desktop.
Save G33kDude/c94ce4a847ac59913ccf52b0a3075f61 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
}
@ennes-ns
Copy link

ennes-ns commented Aug 5, 2022

Hey! Where did you get the Socket library from?

@node-out
Copy link

Hey! Where did you get the Socket library from?

https://github.com/G33kDude/Socket.ahk/tree/master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment