streamdeck

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2025 License: MIT Imports: 19 Imported by: 12

README

streamdeck

Go Report Card Go Reference MIT licensed

streamdeck buttons streamdeck slide show

streamdeck is a library for interfacing with the Elgato/Corsair Stream Deck

This library is written in the programing language Go.

Note

This project is a golang API for the Elgato/Corsair Stream Deck. This library unleashes the power of the StreamDeck. It allows you to completely customize the content of the device, without the need of the OEM's software.

License

streamdeck is published under the permissive MIT license.

Dependencies

There are a few go libraries which are needed at compile time. streamdeck does not have any runtime dependencies.

CGO

Compiling this library requires unfortunately a C compiler since the underlying HID library requires cgo for enumerating the HID devices.

Supported Operating Systems

The library should work on Linux, MacOS and Windows (>=7).

streamdeck works well on SoC boards like the Raspberry / Orange / Banana Pis.

Linux Device rules

On Linux you might have to create an udev rule, to access the streamdeck.

sudo vim /etc/udev/rules.d/99-streamdeck.rules

SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="0060", MODE="0664", GROUP="plugdev"

After saving the udev rule, unplug and plug the streamdeck again into the USB port. For the rule above, your user must be a member of the plugdev group.

Make sure that your streamdeck is correctly recognized by executing:

$ go run examples/enumerate/enumerate.go
Found 1 Elgato Stream Deck(s):
	SerialNumber:        AL12H1A07123

Documentation

The auto generated documentation can be found at godoc.org

Examples

Please checkout the dedicated repository streamdeck-examples for examples.

My personal library of streamdeck elements / buttons can be found in the streamdeck-buttons repository.

Credits

This project would not have been possible without the work of Alex Van Camp. In particular his notes of the StreamDeck's protocol were very helpful. Alex has provided a reference implementation in Javascript / Node.js.

Documentation

Index

Constants

View Source
const (
	EventUnknown = iota
	EventKeyPressed
	EventKeyReleased
	EventDialPressed
	EventDialReleased
	EventDialTurn
)
View Source
const DialMax = 100
View Source
const VendorID = 4057

VendorID is the USB VendorID assigned to Elgato (0x0fd9)

Variables

View Source
var Debug = false
View Source
var MonoMedium *truetype.Font
View Source
var MonoRegular *truetype.Font
View Source
var Original = Config{
	ProductID:        0x60,
	NumButtonColumns: 5,
	NumButtonRows:    3,
	Spacer:           19,
	ButtonSize:       72,
	ImageFormat:      "bmp",
	ConvertKey:       true,
}

Model 20GAA9901

View Source
var Original2 = Config{
	ProductID:        0x80,
	NumButtonColumns: 5,
	NumButtonRows:    3,
	Spacer:           19,
	ButtonSize:       72,
	ImageFormat:      "jpg",
	ImageRotate:      true,
}
View Source
var OriginalMk1 = Config{
	ProductID:        0x6d,
	NumButtonColumns: 5,
	NumButtonRows:    3,
	Spacer:           19,
	ButtonSize:       72,
	ImageFormat:      "jpg",
	ImageRotate:      true,
}

Model 20GAA9902

View Source
var Plus = Config{
	ProductID:        0x0084,
	NumButtonColumns: 4,
	NumButtonRows:    2,
	Spacer:           19,
	ButtonSize:       120,
	ImageFormat:      "jpg",
}

Functions

This section is empty.

Types

type BtnEvent

type BtnEvent func(s State, e Event)

BtnEvent is a callback which gets executed when the state of a button changes, so whenever it gets pressed or released.

type Config added in v1.0.0

type Config struct {
	ProductID        uint16 // ProductID is the USB ProductID
	NumButtonColumns int
	NumButtonRows    int
	Spacer           int // Spacer is the spacing distance (in pixel) of two buttons on the Stream Deck.
	ButtonSize       int
	ImageFormat      string
	ImageRotate      bool
	ConvertKey       bool
}

func FindConnectedConfig added in v1.0.0

func FindConnectedConfig() (Config, bool)

func (Config) NumButtons added in v1.0.0

func (c Config) NumButtons() int

func (*Config) PanelHeight added in v1.0.0

func (c *Config) PanelHeight() int

PanelHeight is the total screen height of the stream deck (including spacers).

func (*Config) PanelWidth added in v1.0.0

func (c *Config) PanelWidth() int

PanelWidth is the total screen width of the Stream Deck (including spacers).

type Event added in v1.0.0

type Event struct {
	Kind  EventKind
	Which int
}

func (Event) String added in v1.0.0

func (e Event) String() string

type EventKind added in v1.0.0

type EventKind int

func (EventKind) String added in v1.0.0

func (ev EventKind) String() string

type State added in v1.0.0

type State struct {
	Keys     []bool
	DialPush []bool
	DialPos  []int // 0 -> 100
}

func (*State) Update added in v1.0.0

func (s *State) Update(c *Config, b []byte) ([]Event, error)

type StreamDeck

type StreamDeck struct {
	Config *Config
	// contains filtered or unexported fields
}

StreamDeck is the object representing the Elgato Stream Deck.

func NewStreamDeck

func NewStreamDeck(serial ...string) (*StreamDeck, error)

NewStreamDeck is the constructor of the StreamDeck object. If several StreamDecks are connected to this PC, the Streamdeck can be selected by supplying the optional serial number of the Device. In the examples folder there is a small program which enumerates all available Stream Decks. If no serial number is supplied, the first StreamDeck found will be selected.

func NewStreamDeckWithConfig added in v1.0.0

func NewStreamDeckWithConfig(c *Config, serial string) (*StreamDeck, error)

NewStreamDeckWithConfig is the constructor for a custom config.

func (*StreamDeck) ClearAllBtns

func (sd *StreamDeck) ClearAllBtns() error

ClearAllBtns fills all keys with the color black

func (*StreamDeck) ClearBtn

func (sd *StreamDeck) ClearBtn(btnIndex int) error

ClearBtn fills a particular key with the color black

func (*StreamDeck) Close

func (sd *StreamDeck) Close() error

Close the connection to the Elgato Stream Deck

func (*StreamDeck) FillColor

func (sd *StreamDeck) FillColor(btnIndex, r, g, b int) error

FillColor fills the given button with a solid color.

func (*StreamDeck) FillImage

func (sd *StreamDeck) FillImage(btnIndex int, img image.Image) error

FillImage fills the given key with an image. For best performance, provide the image in the size of 72x72 pixels. Otherwise it will be automatically resized.

func (*StreamDeck) FillImageFromFile

func (sd *StreamDeck) FillImageFromFile(keyIndex int, path string) error

FillImageFromFile fills the given key with an image from a file.

func (*StreamDeck) FillPanel

func (sd *StreamDeck) FillPanel(img image.Image) error

FillPanel fills the whole panel witn an image. The image is scaled to fit and then center-cropped (if necessary). The native picture size is 360px x 216px.

func (*StreamDeck) FillPanelFromFile

func (sd *StreamDeck) FillPanelFromFile(path string) error

FillPanelFromFile fills the entire panel with an image from a file.

func (*StreamDeck) Serial added in v0.1.9

func (sd *StreamDeck) Serial() string

Serial returns the Serial number of this Elgato Stream Deck

func (*StreamDeck) SetBrightness added in v1.0.0

func (sd *StreamDeck) SetBrightness(b uint16) error

b 0 -> 100

func (*StreamDeck) SetBtnEventCb

func (sd *StreamDeck) SetBtnEventCb(ev BtnEvent)

SetBtnEventCb sets the BtnEvent callback which get's executed whenever a Button event (pressed/released) occures.

func (*StreamDeck) WriteText

func (sd *StreamDeck) WriteText(btnIndex int, textBtn TextButton) error

WriteText can write several lines of Text to a button. It is up to the user to ensure that the lines fit properly on the button.

func (*StreamDeck) WriteTextOnImage added in v1.0.0

func (sd *StreamDeck) WriteTextOnImage(btnIndex int, imgIn image.Image, lines []TextLine) error

WriteText can write several lines of Text to a button. It is up to the user to ensure that the lines fit properly on the button.

type TextButton

type TextButton struct {
	Lines   []TextLine
	BgColor color.Color
}

TextButton holds the lines to be written to a button and the desired Background color.

type TextLine

type TextLine struct {
	Text      string
	PosX      int
	PosY      int
	Font      *truetype.Font
	FontSize  float64
	FontColor color.Color
}

TextLine holds the content of one text line.

Directories

Path Synopsis
cmd
demo command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL