项目作者: clockworksoul

项目描述 :
A simple Go client for the Das Keyboard Q service. Supports both localhost and Q Cloud.
高级语言: Go
项目地址: git://github.com/clockworksoul/daskeyboard-q-client.git
创建时间: 2021-04-28T19:51:21Z
项目社区:https://github.com/clockworksoul/daskeyboard-q-client

开源协议:MIT License

下载


Go Client for Das Keyboard Q Service

A simple Go client that can be used to send messages to a Q-enabled device via a Das Keyboard Q service. It supports both a locally-running service and the official Q Cloud.

Signals may contain lighting color and effect information, as well as a message for a human.

https://www.daskeyboard.io/get-started/

How to use this

This builds a SignalRequest value to trigger a popup message and set the Q key to solid red, which it effects by using the client’s CreateSignal method to send a message to the Q API.

  1. package main
  2. import (
  3. "context"
  4. "encoding/json"
  5. "log"
  6. "time"
  7. qclient "github.com/clockworksoul/daskeyboard-q-client"
  8. )
  9. func main() {
  10. client, err := qclient.New()
  11. if err != nil {
  12. log.Fatal("client error:", err)
  13. }
  14. // Create the signal request. Required fields are the name, color, and zone ID.
  15. // To know more about zone IDs, see https://www.daskeyboard.io/q-zone-id-explanation/.
  16. signal := qclient.NewSignalRequest("New Q app version available", "#FF0000", qclient.KeyQ).
  17. WithMessage("Q App version 3 is available.").
  18. WithEffect(qclient.EffectSetColor)
  19. ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
  20. defer cancel()
  21. // Send the signal creation request to the API. Returns a *SignalResponse
  22. // value or an error.
  23. response, err := client.CreateSignal(ctx, signal)
  24. if err != nil {
  25. log.Fatal("signal creation error:", err)
  26. }
  27. // Return the response as a string, just for fun.
  28. bytes, _ := json.MarshalIndent(response, "", " ")
  29. log.Println(string(bytes))
  30. }

The output would look something like:

  1. {
  2. "name": "New Q app version available",
  3. "message": "Q App version 3 is available.",
  4. "zoneId": "KEY_Q",
  5. "color": "#FF0000",
  6. "effect": "SET_COLOR",
  7. "pid": "Q_MATRIX",
  8. "clientName": "GoClient",
  9. "id": -590,
  10. "userId": 14339,
  11. "createdAt": 1619815234590,
  12. "updatedAt": 1619815234590
  13. }