Help combining AHKv2-Scripts with elgato Stream Deck.
Help combining AHKv2-Scripts with elgato Stream Deck.
Hello there,
Got a Stream Deck recently. Now I want to integrate my AHKv2-scripts on it.
I heavily rely on AHKv2 and internal system calls (dllcall) for achieving my goals on windows.
Since just calling them is a really boring I want to dynamically change the icons on the stream deck depending e.g. on exit code of the ahk script I try to run.
And no, the StreamDeck UI is not able to provide such functionality by drag&drop. You must write your own plugin to achieve that.
Example goal:
Toggling between Single-/Multi-monitor on a button press (instead of using Win+P) and change the according icon to the current monitor-state.
I started to program a StreamDeck plugin in JavaScript because that is how the SDK for it is documented.
To break the process down, it works like this:
You create a websocket on localhost and send JSON-formatted data back and forth over it to modify the StreamDeck-settings on-the-fly. That is the API to communicate with the Streamdeck control server which handles the (HID-)driver requests.
With the JSON-data you can dynamically change the button's information like which png to display and also to save the settings permanently (e.g. state control)
The problem: I've got the button-logic working in Java-Script but I cannot call the AHK-interpreter from it to execute the neccessary code. So this is a dead end, right?
The .manifest inside the Streamdeck Plugin has a property called "CodePathWin". Executables are supported (currently I've got a .html in there to load the JS code) and if I look into other plugins it is indeed a way to achieve things.
Now I realize that I'd need to program a websocket in AHKv2 and a parser for the .JSON format, just to beeing able to communicate with the damn StreamDeck API. I already googled around and I could only find AHKv1 scripts to achieve those goals.
I neither have the time nor the knowhow to convert that to ahkv2.
Are there already written libraries I could use and couldn't find by googling?
Are there people out there who are (mis-)using their StreamDeck like this? How did you do that?
Please help
Sincerly
Got a Stream Deck recently. Now I want to integrate my AHKv2-scripts on it.
I heavily rely on AHKv2 and internal system calls (dllcall) for achieving my goals on windows.
Since just calling them is a really boring I want to dynamically change the icons on the stream deck depending e.g. on exit code of the ahk script I try to run.
And no, the StreamDeck UI is not able to provide such functionality by drag&drop. You must write your own plugin to achieve that.
Example goal:
Toggling between Single-/Multi-monitor on a button press (instead of using Win+P) and change the according icon to the current monitor-state.
I started to program a StreamDeck plugin in JavaScript because that is how the SDK for it is documented.
To break the process down, it works like this:
You create a websocket on localhost and send JSON-formatted data back and forth over it to modify the StreamDeck-settings on-the-fly. That is the API to communicate with the Streamdeck control server which handles the (HID-)driver requests.
With the JSON-data you can dynamically change the button's information like which png to display and also to save the settings permanently (e.g. state control)
The problem: I've got the button-logic working in Java-Script but I cannot call the AHK-interpreter from it to execute the neccessary code. So this is a dead end, right?
The .manifest inside the Streamdeck Plugin has a property called "CodePathWin". Executables are supported (currently I've got a .html in there to load the JS code) and if I look into other plugins it is indeed a way to achieve things.
Now I realize that I'd need to program a websocket in AHKv2 and a parser for the .JSON format, just to beeing able to communicate with the damn StreamDeck API. I already googled around and I could only find AHKv1 scripts to achieve those goals.
I neither have the time nor the knowhow to convert that to ahkv2.
Are there already written libraries I could use and couldn't find by googling?
Are there people out there who are (mis-)using their StreamDeck like this? How did you do that?
Please help
Sincerly
Re: Help combining AHKv2-Scripts with elgato Stream Deck.
uve got v2 libraries here: https://github.com/thqby/ahk2_lib
and then uve got a C# library u can run in ahk with CLR: https://github.com/evilC/AutoHotStreamDeck
https://github.com/Lexikos/CLR.ahk/blob/main/CLR.ahk
shouldnt be too hard to port over to v2, though i cant say if it will work with whatever device u got at home
and then uve got a C# library u can run in ahk with CLR: https://github.com/evilC/AutoHotStreamDeck
https://github.com/Lexikos/CLR.ahk/blob/main/CLR.ahk
shouldnt be too hard to port over to v2, though i cant say if it will work with whatever device u got at home
Re: Help combining AHKv2-Scripts with elgato Stream Deck.
Any documentation/examples on the websocket.ahk class?
It relies solely on dllcalls for winhttp. They are undocumented and I do not get a respond for sending a buffer to the websocket server.
As for the 2nd part. StreamDeckSharp is a library that communicates with the streamdeck driver by itself. It replaces the StreamDeck software.
I still want to use the original software and its plugins that come with the StreamDeck.
It relies solely on dllcalls for winhttp. They are undocumented and I do not get a respond for sending a buffer to the websocket server.
As for the 2nd part. StreamDeckSharp is a library that communicates with the streamdeck driver by itself. It replaces the StreamDeck software.
I still want to use the original software and its plugins that come with the StreamDeck.
Re: Help combining AHKv2-Scripts with elgato Stream Deck.
I've got it working After I installed a standalone websocket server and was able to debug the connection messages I realized that the JSON I send as a registerEvent had multiple spaces inside the brackets. That was enough that the connection was silently rejected by the StreamDeck software.
Now the connection can be established and i can interprete KeyEvents.
Btw. Both approaches work. I can either use the v2 websocket library which is very undocumented... Or I use the webhook approach for IE to inject JS code. Latter is much more human readable. When I finish writing the library I'll post the code on Github so everyone can use it.
Now the connection can be established and i can interprete KeyEvents.
Btw. Both approaches work. I can either use the v2 websocket library which is very undocumented... Or I use the webhook approach for IE to inject JS code. Latter is much more human readable. When I finish writing the library I'll post the code on Github so everyone can use it.
Re: Help combining AHKv2-Scripts with elgato Stream Deck.
I released the code on Github together with an example program.
It is very barebones and in an early stage but it gets the job done. I'll expand and improve it over time.
https://github.com/GothicIII/AHK_StreamDeck_lib
It is very barebones and in an early stage but it gets the job done. I'll expand and improve it over time.
https://github.com/GothicIII/AHK_StreamDeck_lib
Re: Help combining AHKv2-Scripts with elgato Stream Deck.
I'd recommend reviewing my WebSocket library, my JSON library, and my StreamDeck library, as well as the StreamDeck page on the Wiki (which does not have much content yet, but your work could contribute).
These all target v1, but porting to v2 shouldn't be crazy difficult (except for JSON). I think thqby's port of Socket.ahk is a 1:1 port which should make porting the StreamDeck library super easy.
With the websocket library, I see you're taking a similar approach, but doing some things differently/strangely with comments that are wrong about what the code below is doing. You are not creating an instance of the Edge browser, the text IE=Edge means you are creating an instance of the Trident engine targeted at the latest release of IE (specifically, IE=11). Before IE was discontinued, "Edge" in that context was an alias for whatever the latest IE version was. But now that IE is discontinued, it always means 11.
I very strongly recommend to use thqby's websocket library instead though, the dllcalls it uses are going to be more reliable than ActiveX. You can see an example of the library's use in thqby's port of Chrome.ahk.
With the JSON library, you really should be using an actual JSON library. Thqby's library is simple to use.
My StreamDeck library really only facilitates running AHK functions from StreamDeck keys (with no communication back from AHK to the deck) but that covers 99% of everything I want it to do.
These all target v1, but porting to v2 shouldn't be crazy difficult (except for JSON). I think thqby's port of Socket.ahk is a 1:1 port which should make porting the StreamDeck library super easy.
With the websocket library, I see you're taking a similar approach, but doing some things differently/strangely with comments that are wrong about what the code below is doing. You are not creating an instance of the Edge browser, the text IE=Edge means you are creating an instance of the Trident engine targeted at the latest release of IE (specifically, IE=11). Before IE was discontinued, "Edge" in that context was an alias for whatever the latest IE version was. But now that IE is discontinued, it always means 11.
I very strongly recommend to use thqby's websocket library instead though, the dllcalls it uses are going to be more reliable than ActiveX. You can see an example of the library's use in thqby's port of Chrome.ahk.
With the JSON library, you really should be using an actual JSON library. Thqby's library is simple to use.
My StreamDeck library really only facilitates running AHK functions from StreamDeck keys (with no communication back from AHK to the deck) but that covers 99% of everything I want it to do.
Re: Help combining AHKv2-Scripts with elgato Stream Deck.
I updated the websocket library. The old version would crash the script. and ws-min.ahk is implemented through htmlfile's jscript.
Re: Help combining AHKv2-Scripts with elgato Stream Deck.
@geek
Thanks for clearifying my mistake. I was under the impression that IE11 is long gone. That's why I assumed it was an edge instance.
I pretty much used your code as base for the websocket connection because it just worked.
Never did anything with websockets before but I regret that I implemented this code, because of its hacky nature instead of actual reliable code.
(It was a huge help though understanding the protocol)
Since my time is very limited I decided to keep this.
I looked through thqby's libraries and while they appear to be well written (handling exceptions and edge cases) but I hesitate to use them
because I hate using code I do not understand fully. The whole collection has pretty much no comments, relies heavily on dllcalls, regex and variables like 'a'.
My intention was to release a poc written in a small amount of time.
I am no programmer at all and my programming skills are mediocre at best.
At least I have a working button on my StreamDeck xP
Thanks for clearifying my mistake. I was under the impression that IE11 is long gone. That's why I assumed it was an edge instance.
I pretty much used your code as base for the websocket connection because it just worked.
Never did anything with websockets before but I regret that I implemented this code, because of its hacky nature instead of actual reliable code.
(It was a huge help though understanding the protocol)
Since my time is very limited I decided to keep this.
I looked through thqby's libraries and while they appear to be well written (handling exceptions and edge cases) but I hesitate to use them
because I hate using code I do not understand fully. The whole collection has pretty much no comments, relies heavily on dllcalls, regex and variables like 'a'.
My intention was to release a poc written in a small amount of time.
I am no programmer at all and my programming skills are mediocre at best.
At least I have a working button on my StreamDeck xP
Re: Help combining AHKv2-Scripts with elgato Stream Deck.
https://github.com/GothicIII/AHK_StreamDeck_lib
I tried your project, but it gives a mistake and does not start.
I tried your project, but it gives a mistake and does not start.
Re: Help combining AHKv2-Scripts with elgato Stream Deck.
@Xruss — Your last post (not including your extra posts in this thread that were disapproved) showed that the reason for your error was you were trying to run AHK v2 but you had v1 installed. You did not reply to the post telling you that. Please reply here and state whether that is the issue here. And always show the error message. Don’t just say there is an error or mistake without providing any detail.