Skip to content

Commit 1993634

Browse files
committed
add KeyToggle() special key and default value support and Update godoc
1 parent 3c8efdd commit 1993634

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

cmd/color-pos/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func colorPicker() {
2727

2828
func main() {
2929
fmt.Println("color picker: ")
30-
30+
fmt.Println("click the left mouse button to get the value.")
3131
for {
3232
colorPicker()
3333
}

key/goKey.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,7 @@ struct KeyNames{
108108
{ "num9", K_NUMPAD_9 },
109109
{ "num_lock", K_NUMPAD_LOCK },
110110

111-
{"num.", K_NUMPAD_DECIMAL },
112-
{"num+", K_NUMPAD_PLUS },
113-
{"num-", K_NUMPAD_MINUS },
114-
{"num*", K_NUMPAD_MUL },
115-
{"num/", K_NUMPAD_DIV },
116-
{"num_clear", K_NUMPAD_CLEAR },
117-
{"num_enter", K_NUMPAD_ENTER },
118-
{"num_equal", K_NUMPAD_EQUAL },
119-
111+
// todo: removed
120112
{ "numpad_0", K_NUMPAD_0 },
121113
{ "numpad_1", K_NUMPAD_1 },
122114
{ "numpad_2", K_NUMPAD_2 },
@@ -129,6 +121,15 @@ struct KeyNames{
129121
{ "numpad_9", K_NUMPAD_9 },
130122
{ "numpad_lock", K_NUMPAD_LOCK },
131123

124+
{"num.", K_NUMPAD_DECIMAL },
125+
{"num+", K_NUMPAD_PLUS },
126+
{"num-", K_NUMPAD_MINUS },
127+
{"num*", K_NUMPAD_MUL },
128+
{"num/", K_NUMPAD_DIV },
129+
{"num_clear", K_NUMPAD_CLEAR },
130+
{"num_enter", K_NUMPAD_ENTER },
131+
{"num_equal", K_NUMPAD_EQUAL },
132+
132133
{ "lights_mon_up", K_LIGHTS_MON_UP },
133134
{ "lights_mon_down", K_LIGHTS_MON_DOWN },
134135
{ "lights_kbd_toggle",K_LIGHTS_KBD_TOGGLE },

robotgo.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,13 @@ func SetMouseDelay(delay int) {
650650
// See keys:
651651
// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md
652652
//
653+
// Examples:
654+
// robotgo.KeyTap("a")
655+
// robotgo.KeyTap("i", "alt", "command")
656+
//
657+
// arr := []string{"alt", "command"}
658+
// robotgo.KeyTap("i", arr)
659+
//
653660
func KeyTap(tapKey string, args ...interface{}) string {
654661
var (
655662
akey string
@@ -672,6 +679,7 @@ func KeyTap(tapKey string, args ...interface{}) string {
672679
zkey := C.CString(tapKey)
673680
defer C.free(unsafe.Pointer(zkey))
674681

682+
// args not key delay
675683
if len(args) > 2 && (reflect.TypeOf(args[2]) != reflect.TypeOf(num)) {
676684
num = len(args)
677685
for i := 0; i < num; i++ {
@@ -685,6 +693,7 @@ func KeyTap(tapKey string, args ...interface{}) string {
685693
return C.GoString(str)
686694
}
687695

696+
// key delay
688697
if len(args) > 0 {
689698
if reflect.TypeOf(args[0]) == reflect.TypeOf(keyArr) {
690699

@@ -736,12 +745,29 @@ func KeyTap(tapKey string, args ...interface{}) string {
736745
return C.GoString(str)
737746
}
738747

739-
// KeyToggle toggle the keyboard
748+
// KeyToggle toggle the keyboard, if there not have args default is "down"
740749
//
741750
// See keys:
742751
// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md
743752
//
753+
// Examples:
754+
// robotgo.KeyToggle("a")
755+
// robotgo.KeyToggle("a", "up")
756+
//
757+
// robotgo.KeyToggle("a", "up", "alt", "cmd")
758+
//
744759
func KeyToggle(key string, args ...string) string {
760+
if len(args) <= 0 {
761+
args = append(args, "down")
762+
}
763+
764+
if _, ok := Special[key]; ok {
765+
key = Special[key]
766+
if len(args) <= 1 {
767+
args = append(args, "shift")
768+
}
769+
}
770+
745771
ckey := C.CString(key)
746772
defer C.free(unsafe.Pointer(ckey))
747773

@@ -757,6 +783,7 @@ func KeyToggle(key string, args ...string) string {
757783
return C.GoString(str)
758784
}
759785

786+
// use key_toggle()
760787
var (
761788
down, mKey, mKeyT = "null", "null", "null"
762789
// keyDelay = 10

0 commit comments

Comments
 (0)