Created
March 12, 2022 19:20
-
-
Save G33kDude/c94ce4a847ac59913ccf52b0a3075f61 to your computer and use it in GitHub Desktop.
Launch AutoHotkey code from a StreamDeck efficiently using GET requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
} |
Hey! Where did you get the Socket library from?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey! Where did you get the Socket library from?