add KeyToggle() special key and default value support and Update godoc

This commit is contained in:
vcaesar 2021-11-08 10:45:38 -04:00
parent 3c8efddb74
commit 19936348de
3 changed files with 39 additions and 11 deletions

View File

@ -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()
}

View File

@ -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 },

View File

@ -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