press empty to release and defer close
parent
4c233cf794
commit
ecbce05cf3
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue