Merge pull request #455 from go-vgo/bitmap-pr

Add more keyUp args and SetDelay() support, add more test code
This commit is contained in:
Evans 2022-02-02 21:22:50 -08:00 committed by GitHub
commit c61fe44788
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 10 deletions

31
key.go
View File

@ -379,9 +379,9 @@ func keyTaps(k string, keyArr []string) error {
}
func keyToggles(k string, keyArr []string) error {
down := false
if keyArr[0] == "down" {
down = true
down := true
if keyArr[0] == "up" {
down = false
}
flags := getFlagsFromValue(keyArr)
@ -494,24 +494,24 @@ func KeyToggle(key string, args ...string) error {
}
// KeyPress press key string
func KeyPress(key string) error {
err := KeyDown(key)
func KeyPress(key string, args ...string) error {
err := KeyDown(key, args...)
if err != nil {
return err
}
MilliSleep(1 + rand.Intn(3))
return KeyUp(key)
return KeyUp(key, args...)
}
// KeyDown press down a key
func KeyDown(key string) error {
return KeyToggle(key)
func KeyDown(key string, args ...string) error {
return KeyToggle(key, args...)
}
// KeyUp press up a key
func KeyUp(key string) error {
return KeyToggle(key, "up")
func KeyUp(key string, args ...string) error {
return KeyToggle(key, append(args, "up")...)
}
// ReadAll read string from clipboard
@ -645,3 +645,14 @@ func TypeStringDelayed(str string, delay int) {
tt.Drop("TypeStringDelayed", "TypeStrDelay")
TypeStrDelay(str, delay)
}
// SetDelay set the key and mouse delay
func SetDelay(d ...int) {
v := 10
if len(d) > 0 {
v = d[0]
}
KeySleep = v
MouseSleep = v
}

View File

@ -117,6 +117,14 @@ func TestKey(t *testing.T) {
e = KeyToggle("v", "up")
tt.Nil(t, e)
e = KeyDown("a")
tt.Nil(t, e)
e = KeyUp("a")
tt.Nil(t, e)
e = KeyPress("b")
tt.Nil(t, e)
}
func TestClip(t *testing.T) {
@ -149,6 +157,9 @@ func TestKeyCode(t *testing.T) {
s := Special["+"]
tt.Equal(t, "=", s)
tt.Equal(t, "0", Key0)
tt.Equal(t, "a", KeyA)
}
func TestImage(t *testing.T) {