press empty to release and defer close
This commit is contained in:
@@ -32,14 +32,22 @@ func (kb Keyboard) wait() {
|
|||||||
func (kb Keyboard) Press(keys ...int) {
|
func (kb Keyboard) Press(keys ...int) {
|
||||||
kb.wait()
|
kb.wait()
|
||||||
|
|
||||||
kb.Release()
|
kb.release()
|
||||||
|
if len(keys) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
kb.kb.SetKeys(keys...)
|
kb.kb.SetKeys(keys...)
|
||||||
if err := kb.kb.Press(); err != nil {
|
if err := kb.kb.Press(); err != nil {
|
||||||
log.Println("failed to press keys:", err)
|
log.Println("failed to press keys:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kb Keyboard) Release() {
|
func (kb Keyboard) Close() {
|
||||||
|
kb.release()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kb Keyboard) release() {
|
||||||
kb.wait()
|
kb.wait()
|
||||||
|
|
||||||
if err := kb.kb.Release(); err != nil {
|
if err := kb.kb.Release(); err != nil {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func TestKeyboardIntegration(t *testing.T) {
|
func TestKeyboardIntegration(t *testing.T) {
|
||||||
kb := output.NewKeyboard()
|
kb := output.NewKeyboard()
|
||||||
defer kb.Release()
|
t.Cleanup(kb.Close)
|
||||||
|
|
||||||
t.Log("pressing 'a' for 5 seconds")
|
t.Log("pressing 'a' for 5 seconds")
|
||||||
kb.Press(output.A)
|
kb.Press(output.A)
|
||||||
@@ -19,5 +19,5 @@ func TestKeyboardIntegration(t *testing.T) {
|
|||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
t.Logf("releasing")
|
t.Logf("releasing")
|
||||||
kb.Release()
|
kb.Press()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user