AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post your working scripts, libraries and tools
User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by evilC » 03 Aug 2018, 15:10

AutoHotStreamDeck (AHSD) is an AHK wrapper for the Elgato Stream Deck

AHSD allows you to:
Subscribe to key events (Press / Release) and set the image for each key.
Add one or more images to keys
Add one or more blocks of text to keys
Set background color for keys
Toggle visibility of layers on keys (Show/hide text or images)

Here is an example of AHSD in action:
Image

Thisis the AHK code used in the video:

Code: Select all

#SingleInstance force
#Persistent
#include Lib\AutoHotStreamDeck.ahk

ActiveProfile := 0
Canvases := []
SubCanvases := []
ToggleStates := []

AHSD := new AutoHotStreamDeck()

keyCount := AHSD.Instance.Deck.KeyCount
rowCount := AHSD.Instance.Deck.RowCount
colCount := AHSD.Instance.Deck.ColumnCount

pageStart := (rowCount - 1) * colCount

Loop % colCount {
	page := A_Index
	letter := Chr(page+64)
	pos := pageStart + page
	r := Rand(), g := Rand(), b := Rand()
	
	AHSD.Instance.SubscribeKey(pos, Func("PageKeyEvent").Bind(A_Index))

	canvas := CreateCanvas("P " letter, r, g, b)
	AHSD.Instance.SetKeyCanvas(pos, canvas)
	Canvases[page] := canvas

	ToggleStates[page] := []
	SubCanvases[page] := []
	Loop % colCount * 2 {
		AHSD.Instance.SubscribeKey(A_Index, Func("KeyEvent").Bind(A_Index))
		canvas := CreateCanvas(letter " " A_Index, r, g, b)
		
		SubCanvases[page, A_Index] := canvas
		ToggleStates[page, A_Index] := 0
	}
}

SetPage(1)
return

CreateCanvas(text, r, g, b){
	global AHSD 
	canvas := AHSD.Instance.CreateKeyCanvas()
	canvas.SetBackground(r, g, b)
	
	stateText := canvas.CreateTextBlock("Pressed").SetHeight(36)
	canvas.AddTextBlock("StateLabel", stateText)
	SetStateLabel(canvas, false)

	buttonText := canvas.CreateTextBlock(text).SetHeight(36).SetTop(36)
	buttonText.SetFontSize(25)
	buttonText.SetOutlineSize(5)
	canvas.AddTextBlock("ButtonLabel", buttonText)
	
	canvas.AddImage("Off", AHSD.Instance.CreateImageFromFileName(A_ScriptDir "\SwitchHOff.png"))
	canvas.AddImage("On", AHSD.Instance.CreateImageFromFileName(A_ScriptDir "\SwitchHOn.png"))

	SetToggleState(canvas, 0)
	return canvas
}

KeyEvent(key, state){
	global AHSD, Canvases, SubCanvases, ActiveProfile, ToggleStates
	;~ ToolTip % "Key: " key ", State: " state
	canvas := SubCanvases[ActiveProfile, key]
	SetStateLabel(canvas, state)
	if (state){
		ToggleStates[key] := !ToggleStates[key]
		SetToggleState(canvas, ToggleStates[key])
	}
	AHSD.Instance.RefreshKey(key)
}

PageKeyEvent(page, state){
	global AHSD, Canvases, SubCanvases, ActiveProfile, pageStart
	
	canvas := Canvases[page]
	SetStateLabel(canvas, state)
	
	SetToggleState(canvas, 1)
	AHSD.Instance.RefreshKey(pageStart + page)
	
	if (page == ActiveProfile)
		return

	SetToggleState(Canvases[ActiveProfile], 0)
	AHSD.Instance.RefreshKey(pageStart + ActiveProfile)

	Loop % AHSD.Instance.Deck.ColumnCount * 2 {
		AHSD.Instance.SetKeyCanvas(A_Index, SubCanvases[page, A_Index])
	}
	ActiveProfile := page
}

SetPage(page){
	PageKeyEvent(page, 1)
	PageKeyEvent(page, 0)
}

SetStateLabel(canvas, state){
	canvas.SetTextBlockVisible("StateLabel", state)
}

SetToggleState(canvas, state){
	if (state){
		canvas.SetImageVisible("Off", false)
		canvas.SetImageVisible("On", true)
	} else {
		canvas.SetImageVisible("On", false)
		canvas.SetImageVisible("Off", true)
	}
}

GetRandomColor(){
	global AHSD
	return AHSD.Instance.CreateBitmapFromColor(Rand(), Rand(), Rand())
}

Rand(){
	Random, val, 0, 255
	return val
}

^Esc::
	ExitApp
GitHub Page (Downloads, Documentation etc)
Last edited by evilC on 05 Aug 2018, 13:44, edited 1 time in total.

User avatar
Nextron
Posts: 1378
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by Nextron » 03 Aug 2018, 16:56

Very nice! :thumbup: Fancy stuff.

When I first saw them I was startled by the price for an external keypad... then I realized the graphical display buttons which opens up possibilities not just for key identification but status feedback too. :mrgreen:

Do you already have a use case in mind?

User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by evilC » 03 Aug 2018, 18:09

I bought it so that I could investigate ways of integrating devices like this into the new UCR-C#
As often when I look into writing new providers for UCR-C#, I start off by writing an AHK wrapper.

User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by evilC » 05 Aug 2018, 13:47

AHSD 0.1.0 released

Keys are now a Canvas object
For now I just added the ability to add TextBlock and Image controls, but in theory, any of the WPF controls could be added.
I also used a custom TextBlock control I found on StackOverflow that does outlining of text, so you can set stroke size, RBGA color etc.

User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by evilC » 06 Aug 2018, 13:38

AHSD 0.2.0 released

Each KeyCanvas class now has a callback.
If the KeyCanvas is loaded into a key slot (ie is visible) and the key is pressed, then that specific callback will fire.

This is so that if you have shift states / layers etc where you load and unload KeyCanvases, then the callback for a specific KeyCanvas will only fire when it is loaded, and irrespective of what key number it is.

Adrulesok99
Posts: 2
Joined: 19 Sep 2018, 10:03

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by Adrulesok99 » 20 Sep 2018, 01:52

Hi,

I've written a (mega) basic code in AHK which selects a window and activates a hotkey in that window:

ifwinexist, Eurex FGBL Dec18 ;identifies window
winactivate ;activates it
send, {space} ;re-centres
sleep 100 ;delay in milliseconds - could speed up if want
send, +t ;triggers liquidate hotkey (+{F1} and +{F12} are market orders)
return

I'm far from experienced coder (used matlab at Uni 10 years ago so have some basic understanding) but pretty sure I can assign this to a hotkey.

My question is, does AHK recognise hotkeys on an Elgato streamdeck? i.e. if i buy one, should it be straight forward enough to set it up so that that a hotkey on the streamdeck runs a script?

Thanks for your help,

Adam

User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by evilC » 20 Sep 2018, 18:35

You do not need this library to see hotkeys coming from a streamdeck, normal AHK scripts can do that.
This library allows you to respond *directly* to the button presses on a streamdeck, without using a keyboard key as a transport mechanism.
It would also let you draw the text "Activate Window" on the button of the streamdeck.

bastage
Posts: 5
Joined: 15 Sep 2017, 00:44

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by bastage » 21 Oct 2018, 19:18

I didn't even know Stream Decks were a thing last week and now that I've got one can't find enough things to do with it so this is fantastic.

I'm able to functionally understand your example (mostly :?) but is there a more straightforward documentation page I'm missing or is that still in the works ..?

Side note: Holy cow you've got some amazing stuff -- I started cringing at the potential amount of time I'm about to lose coming up with ways to save myself time. :clap:

Thanks ..!

User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by evilC » 22 Oct 2018, 15:47

I never quite got around to the documentation, although I did try to provide as many examples as I could.
Will see if I can get around to it at some point soon, but I am pretty busy lately.
Warning: A lot of my repos are in a semi-finished state, don't expect everything to work...

bastage
Posts: 5
Joined: 15 Sep 2017, 00:44

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by bastage » 22 Oct 2018, 17:11

Understood and no problem at all -- I've been working through the examples but just wanted to confirm.

As mentioned as soon as I found out about the Stream Deck I started thinking about all kinds of ways to have it hook into AHK, but to find out I could use AHK to drive it was really exciting.

Kind of a vague, open side question but if "all" I want to do is do some basic programmatic running of the Stream Deck (not sure what I want exactly yet but probably not much more than being able to use a few config files with AHK to populate/run some semi-dynamic Stream Deck "pages") is using your wrapper all I'll likely need ..?

More specifically, while browsing around yesterday I saw things like this Node JS application (stream-deck-driver) which looked like it could kinda do what I wanted but since I know AHK was hoping to drive it more from that direction. (Really at this point I'm still just kind of spinning in circles thinking about the various things I want to do with it so still in "wild discovery mode".)

Again, thanks for all the cool stuff.

User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by evilC » 23 Oct 2018, 08:08

The Node.js library may allow you to run JS code in response to button presses on the SD, but (AFAIK) Node does not have commands to send Keypresses etc.
If you want to take Windows-specific actions (eg sending keypresses, manipulating windows etc) in response to SD keypresses, then you want my library.

bastage
Posts: 5
Joined: 15 Sep 2017, 00:44

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by bastage » 23 Oct 2018, 12:42

Yeah, my (clumsy) plan with the Node.js library was to have each one point to an AHK script to do whatever but I'm going to stick with yours.

Thanks for the feedback.

birdie2018
Posts: 2
Joined: 10 Jun 2018, 12:34

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by birdie2018 » 29 Oct 2018, 06:09

Great script love it but as a newb to AHK I'm trying to get my head around this scripting language, I fairly good at breaking down things and understanding things, is there any way you can show a real world running script say setting variables to be used within a script controlled by AutoHotStreamDeck , or even just how I could implement this into a current script, I have seen the example and understand what it can do but a better examples would help ppl like me imo, thank you for your work

User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by evilC » 29 Oct 2018, 13:38

birdie2018 wrote:
29 Oct 2018, 06:09
is there any way you can show a real world running script say setting variables to be used within a script controlled by AutoHotStreamDeck
Not quite sure what you mean here.
One AHK script cannot set variables in another AHK script without fancy inter-script communication, which is way outside the scope of this thread.
If you have an existing script which you want to use with AHSD, you need to re-write the script using AHSD.

thejack473
Posts: 4
Joined: 21 Feb 2017, 07:30

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by thejack473 » 06 Sep 2019, 06:08

sorry for my quite possibly silly question, but how do you install this wrapper and how does it then call on functions in my scripts?
currently i use the Elgato software to open every single script individually, though i'd like it to just have one large script with program specific functions.
this is the issue when you have a total of 886 scripts, just too many key combinations to keep in mind. so i kinda need it to hook directly

User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by evilC » 06 Sep 2019, 07:24

There is no installation, AHK scripts do not need to be installed
You cannot use it to call functions in other scripts, as AHK does not support this
Code within an AHSD script creates a button on an SD device, which you then point at a function in that same script
I am not sure if you can run multiple AHSD scripts at once and interface with the same SD, I have never tried it

thejack473
Posts: 4
Joined: 21 Feb 2017, 07:30

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by thejack473 » 06 Sep 2019, 08:01

oh, i might just be a bit too much of a novice, then. since i tried running all of the scripts but it said it couldn't get deck on line 12 in your example.
anywho, i guess for my purposes i'll just keep it as-is.
though redirecting does seem to be a thing according to Taran from LTT: https youtu.be /vhPLhfP1b_s?t=295 Broken Link for safety


bar3nd
Posts: 3
Joined: 18 Nov 2019, 08:24

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by bar3nd » 18 Nov 2019, 08:29

Hi,

Thanks for the work on this. I've been using Streamdeck in combination with Autohotkeys for a while, but what I'd like to do is set the button graphic to a specific image on disk: so specify a file path. It seems Autohotstreamdeck can do this, but my programming skills are too limited to make sense of the example script.

Could you point me to a start? Basically load a given image into the button that was just clicked.

Thanks,

Bar3nd

User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

Re: AutoHotStreamDeck - AHK wrapper for Elgato Stream Deck (Keys with screens in them!)

Post by evilC » 20 Nov 2019, 05:39

You add an image to a canvas object

Code: Select all

#SingleInstance force
#Persistent
#include Lib\AutoHotStreamDeck.ahk

AHSD := new AutoHotStreamDeck()

; Get a Deck object
Deck := AHSD.Instance.GetDeck(1)

; Ask the Deck object to create a new Canvas Object
canvas := Deck.CreateKeyCanvas(Func("KeyEvent"))

; Set a picture for the key
canvas.AddImage("On", AHSD.Instance.CreateImageFromFileName(A_ScriptDir "\SwitchHOn.png"))

; Assign the Canvas Object to key 1 (Imagery uploaded to key's screen at this point)
Deck.SetKeyCanvas(1, canvas)
return

KeyEvent(state){
	Tooltip % "key changed state to: " state
}

^Esc::
	ExitApp

Post Reply

Return to “Scripts and Functions”