mirror of
https://github.com/Luzifer/streamdeck.git
synced 2024-12-21 02:01:24 +00:00
Add support for raw key codes
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
c8a6c79369
commit
d68422f759
1 changed files with 37 additions and 22 deletions
|
@ -15,23 +15,33 @@ func init() {
|
||||||
type actionKeyPress struct{}
|
type actionKeyPress struct{}
|
||||||
|
|
||||||
func (actionKeyPress) Execute(attributes map[string]interface{}) error {
|
func (actionKeyPress) Execute(attributes map[string]interface{}) error {
|
||||||
keys, ok := attributes["keys"].([]interface{})
|
|
||||||
if !ok {
|
|
||||||
return errors.New("No keys array present")
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
delay time.Duration
|
delay time.Duration
|
||||||
keyCodes []uint16
|
execCodes []uint16
|
||||||
|
ok bool
|
||||||
|
|
||||||
|
keyNames []interface{}
|
||||||
|
keyCodes []interface{}
|
||||||
|
useKeyNames bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
keyCodes, ok = attributes["key_codes"].([]interface{})
|
||||||
|
if !ok {
|
||||||
|
keyNames, ok = attributes["keys"].([]interface{})
|
||||||
|
if !ok {
|
||||||
|
return errors.New("No key_codes or keys array present")
|
||||||
|
}
|
||||||
|
useKeyNames = true
|
||||||
|
}
|
||||||
|
|
||||||
if v, ok := attributes["delay"].(string); ok {
|
if v, ok := attributes["delay"].(string); ok {
|
||||||
if d, err := time.ParseDuration(v); err == nil {
|
if d, err := time.ParseDuration(v); err == nil {
|
||||||
delay = d
|
delay = d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, k := range keys {
|
if useKeyNames {
|
||||||
|
for _, k := range keyNames {
|
||||||
// Convert misdetections into strings
|
// Convert misdetections into strings
|
||||||
switch k.(type) {
|
switch k.(type) {
|
||||||
case int:
|
case int:
|
||||||
|
@ -40,7 +50,7 @@ func (actionKeyPress) Execute(attributes map[string]interface{}) error {
|
||||||
|
|
||||||
if kv, ok := k.(string); ok {
|
if kv, ok := k.(string); ok {
|
||||||
if kc, ok := uinputKeyMapping[kv]; ok {
|
if kc, ok := uinputKeyMapping[kv]; ok {
|
||||||
keyCodes = append(keyCodes, kc)
|
execCodes = append(execCodes, kc)
|
||||||
} else {
|
} else {
|
||||||
return errors.Errorf("Unknown key %q", kv)
|
return errors.Errorf("Unknown key %q", kv)
|
||||||
}
|
}
|
||||||
|
@ -48,6 +58,11 @@ func (actionKeyPress) Execute(attributes map[string]interface{}) error {
|
||||||
return errors.New("Unknown key type detected")
|
return errors.New("Unknown key type detected")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for _, k := range keyCodes {
|
||||||
|
execCodes = append(execCodes, uint16(k.(int)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if v, ok := attributes["mod_shift"].(bool); ok && v {
|
if v, ok := attributes["mod_shift"].(bool); ok && v {
|
||||||
if err := kbd.KeyDown(uinput.KeyLeftShift); err != nil {
|
if err := kbd.KeyDown(uinput.KeyLeftShift); err != nil {
|
||||||
|
@ -70,7 +85,7 @@ func (actionKeyPress) Execute(attributes map[string]interface{}) error {
|
||||||
defer kbd.KeyUp(uinput.KeyLeftCtrl)
|
defer kbd.KeyUp(uinput.KeyLeftCtrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, kc := range keyCodes {
|
for _, kc := range execCodes {
|
||||||
if err := kbd.KeyPress(kc); err != nil {
|
if err := kbd.KeyPress(kc); err != nil {
|
||||||
return errors.Wrap(err, "Unable to press key")
|
return errors.Wrap(err, "Unable to press key")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue