From 19936348de261e1380fc51e7925b500b5da11ec9 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Mon, 8 Nov 2021 10:45:38 -0400 Subject: [PATCH] add KeyToggle() special key and default value support and Update godoc --- cmd/color-pos/main.go | 2 +- key/goKey.h | 19 ++++++++++--------- robotgo.go | 29 ++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/cmd/color-pos/main.go b/cmd/color-pos/main.go index b4ec4f9..64e4dcb 100644 --- a/cmd/color-pos/main.go +++ b/cmd/color-pos/main.go @@ -27,7 +27,7 @@ func colorPicker() { func main() { fmt.Println("color picker: ") - + fmt.Println("click the left mouse button to get the value.") for { colorPicker() } diff --git a/key/goKey.h b/key/goKey.h index 031162f..29dfa31 100644 --- a/key/goKey.h +++ b/key/goKey.h @@ -108,15 +108,7 @@ struct KeyNames{ { "num9", K_NUMPAD_9 }, { "num_lock", K_NUMPAD_LOCK }, - {"num.", K_NUMPAD_DECIMAL }, - {"num+", K_NUMPAD_PLUS }, - {"num-", K_NUMPAD_MINUS }, - {"num*", K_NUMPAD_MUL }, - {"num/", K_NUMPAD_DIV }, - {"num_clear", K_NUMPAD_CLEAR }, - {"num_enter", K_NUMPAD_ENTER }, - {"num_equal", K_NUMPAD_EQUAL }, - + // todo: removed { "numpad_0", K_NUMPAD_0 }, { "numpad_1", K_NUMPAD_1 }, { "numpad_2", K_NUMPAD_2 }, @@ -129,6 +121,15 @@ struct KeyNames{ { "numpad_9", K_NUMPAD_9 }, { "numpad_lock", K_NUMPAD_LOCK }, + {"num.", K_NUMPAD_DECIMAL }, + {"num+", K_NUMPAD_PLUS }, + {"num-", K_NUMPAD_MINUS }, + {"num*", K_NUMPAD_MUL }, + {"num/", K_NUMPAD_DIV }, + {"num_clear", K_NUMPAD_CLEAR }, + {"num_enter", K_NUMPAD_ENTER }, + {"num_equal", K_NUMPAD_EQUAL }, + { "lights_mon_up", K_LIGHTS_MON_UP }, { "lights_mon_down", K_LIGHTS_MON_DOWN }, { "lights_kbd_toggle",K_LIGHTS_KBD_TOGGLE }, diff --git a/robotgo.go b/robotgo.go index 6d649b4..cc6f257 100644 --- a/robotgo.go +++ b/robotgo.go @@ -650,6 +650,13 @@ func SetMouseDelay(delay int) { // See keys: // https://github.com/go-vgo/robotgo/blob/master/docs/keys.md // +// Examples: +// robotgo.KeyTap("a") +// robotgo.KeyTap("i", "alt", "command") +// +// arr := []string{"alt", "command"} +// robotgo.KeyTap("i", arr) +// func KeyTap(tapKey string, args ...interface{}) string { var ( akey string @@ -672,6 +679,7 @@ func KeyTap(tapKey string, args ...interface{}) string { zkey := C.CString(tapKey) defer C.free(unsafe.Pointer(zkey)) + // args not key delay if len(args) > 2 && (reflect.TypeOf(args[2]) != reflect.TypeOf(num)) { num = len(args) for i := 0; i < num; i++ { @@ -685,6 +693,7 @@ func KeyTap(tapKey string, args ...interface{}) string { return C.GoString(str) } + // key delay if len(args) > 0 { if reflect.TypeOf(args[0]) == reflect.TypeOf(keyArr) { @@ -736,12 +745,29 @@ func KeyTap(tapKey string, args ...interface{}) string { return C.GoString(str) } -// KeyToggle toggle the keyboard +// KeyToggle toggle the keyboard, if there not have args default is "down" // // See keys: // https://github.com/go-vgo/robotgo/blob/master/docs/keys.md // +// Examples: +// robotgo.KeyToggle("a") +// robotgo.KeyToggle("a", "up") +// +// robotgo.KeyToggle("a", "up", "alt", "cmd") +// func KeyToggle(key string, args ...string) string { + if len(args) <= 0 { + args = append(args, "down") + } + + if _, ok := Special[key]; ok { + key = Special[key] + if len(args) <= 1 { + args = append(args, "shift") + } + } + ckey := C.CString(key) defer C.free(unsafe.Pointer(ckey)) @@ -757,6 +783,7 @@ func KeyToggle(key string, args ...string) string { return C.GoString(str) } + // use key_toggle() var ( down, mKey, mKeyT = "null", "null", "null" // keyDelay = 10