diff --git a/robotgo.go b/robotgo.go index 08ab002..5ac3edd 100644 --- a/robotgo.go +++ b/robotgo.go @@ -63,6 +63,7 @@ import ( "unsafe" // "syscall" + "math/rand" "os/exec" "github.com/go-vgo/robotgo/clipboard" @@ -697,6 +698,23 @@ func KeyToggle(key string, args ...string) string { return C.GoString(str) } +// KeyPress press key string +func KeyPress(key string) { + KeyDown(key) + Sleep(15 + rand.Intn(10)) + KeyUp(key) +} + +// KeyDown press down a key +func KeyDown(key string) { + KeyToggle(key, "down") +} + +// KeyUp press up a key +func KeyUp(key string) { + KeyToggle(key, "up") +} + // ReadAll read string from clipboard func ReadAll() (string, error) { return clipboard.ReadAll()