press empty to release and defer close

master
bel 2023-03-01 21:11:26 -07:00
parent 4c233cf794
commit ecbce05cf3
2 changed files with 12 additions and 4 deletions

View File

@ -32,14 +32,22 @@ func (kb Keyboard) wait() {
func (kb Keyboard) Press(keys ...int) {
kb.wait()
kb.Release()
kb.release()
if len(keys) == 0 {
return
}
kb.kb.SetKeys(keys...)
if err := kb.kb.Press(); err != nil {
log.Println("failed to press keys:", err)
}
}
func (kb Keyboard) Release() {
func (kb Keyboard) Close() {
kb.release()
}
func (kb Keyboard) release() {
kb.wait()
if err := kb.kb.Release(); err != nil {

View File

@ -10,7 +10,7 @@ import (
func TestKeyboardIntegration(t *testing.T) {
kb := output.NewKeyboard()
defer kb.Release()
t.Cleanup(kb.Close)
t.Log("pressing 'a' for 5 seconds")
kb.Press(output.A)
@ -19,5 +19,5 @@ func TestKeyboardIntegration(t *testing.T) {
time.Sleep(time.Second)
}
t.Logf("releasing")
kb.Release()
kb.Press()
}