mirror of https://github.com/jetkvm/kvm.git
chore: clear keysDownState
This commit is contained in:
parent
a667aefc96
commit
d6de9668bd
16
jsonrpc.go
16
jsonrpc.go
|
@ -1,6 +1,7 @@
|
||||||
package kvm
|
package kvm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -1102,6 +1103,12 @@ func rpcCancelKeyboardMacro() {
|
||||||
cancelKeyboardMacro()
|
cancelKeyboardMacro()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var keyboardClearStateKeys = make([]byte, 6)
|
||||||
|
|
||||||
|
func isClearKeyStep(step hidrpc.KeyboardMacro) bool {
|
||||||
|
return step.Modifier == 0 && bytes.Equal(step.Keys, keyboardClearStateKeys)
|
||||||
|
}
|
||||||
|
|
||||||
func rpcDoExecuteKeyboardMacro(ctx context.Context, macro []hidrpc.KeyboardMacro) (usbgadget.KeysDownState, error) {
|
func rpcDoExecuteKeyboardMacro(ctx context.Context, macro []hidrpc.KeyboardMacro) (usbgadget.KeysDownState, error) {
|
||||||
var last usbgadget.KeysDownState
|
var last usbgadget.KeysDownState
|
||||||
var err error
|
var err error
|
||||||
|
@ -1117,13 +1124,20 @@ func rpcDoExecuteKeyboardMacro(ctx context.Context, macro []hidrpc.KeyboardMacro
|
||||||
return last, err
|
return last, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// notify the device that the keyboard state is being cleared
|
||||||
|
if isClearKeyStep(step) {
|
||||||
|
gadget.UpdateKeysDown(0, keyboardClearStateKeys)
|
||||||
|
}
|
||||||
|
|
||||||
// Use context-aware sleep that can be cancelled
|
// Use context-aware sleep that can be cancelled
|
||||||
select {
|
select {
|
||||||
case <-time.After(delay):
|
case <-time.After(delay):
|
||||||
// Sleep completed normally
|
// Sleep completed normally
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
// make sure keyboard state is reset
|
// make sure keyboard state is reset
|
||||||
rpcKeyboardReport(0, make([]byte, 6))
|
rpcKeyboardReport(0, keyboardClearStateKeys)
|
||||||
|
gadget.UpdateKeysDown(0, keyboardClearStateKeys)
|
||||||
|
|
||||||
logger.Debug().Int("step", i).Msg("Keyboard macro cancelled during sleep")
|
logger.Debug().Int("step", i).Msg("Keyboard macro cancelled during sleep")
|
||||||
return last, ctx.Err()
|
return last, ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue