mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 14:43:55 +00:00
add KeyToggle() special key and default value support and Update godoc
This commit is contained in:
parent
3c8efddb74
commit
19936348de
@ -27,7 +27,7 @@ func colorPicker() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("color picker: ")
|
fmt.Println("color picker: ")
|
||||||
|
fmt.Println("click the left mouse button to get the value.")
|
||||||
for {
|
for {
|
||||||
colorPicker()
|
colorPicker()
|
||||||
}
|
}
|
||||||
|
19
key/goKey.h
19
key/goKey.h
@ -108,15 +108,7 @@ struct KeyNames{
|
|||||||
{ "num9", K_NUMPAD_9 },
|
{ "num9", K_NUMPAD_9 },
|
||||||
{ "num_lock", K_NUMPAD_LOCK },
|
{ "num_lock", K_NUMPAD_LOCK },
|
||||||
|
|
||||||
{"num.", K_NUMPAD_DECIMAL },
|
// todo: removed
|
||||||
{"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 },
|
|
||||||
|
|
||||||
{ "numpad_0", K_NUMPAD_0 },
|
{ "numpad_0", K_NUMPAD_0 },
|
||||||
{ "numpad_1", K_NUMPAD_1 },
|
{ "numpad_1", K_NUMPAD_1 },
|
||||||
{ "numpad_2", K_NUMPAD_2 },
|
{ "numpad_2", K_NUMPAD_2 },
|
||||||
@ -129,6 +121,15 @@ struct KeyNames{
|
|||||||
{ "numpad_9", K_NUMPAD_9 },
|
{ "numpad_9", K_NUMPAD_9 },
|
||||||
{ "numpad_lock", K_NUMPAD_LOCK },
|
{ "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_up", K_LIGHTS_MON_UP },
|
||||||
{ "lights_mon_down", K_LIGHTS_MON_DOWN },
|
{ "lights_mon_down", K_LIGHTS_MON_DOWN },
|
||||||
{ "lights_kbd_toggle",K_LIGHTS_KBD_TOGGLE },
|
{ "lights_kbd_toggle",K_LIGHTS_KBD_TOGGLE },
|
||||||
|
29
robotgo.go
29
robotgo.go
@ -650,6 +650,13 @@ func SetMouseDelay(delay int) {
|
|||||||
// See keys:
|
// See keys:
|
||||||
// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md
|
// 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 {
|
func KeyTap(tapKey string, args ...interface{}) string {
|
||||||
var (
|
var (
|
||||||
akey string
|
akey string
|
||||||
@ -672,6 +679,7 @@ func KeyTap(tapKey string, args ...interface{}) string {
|
|||||||
zkey := C.CString(tapKey)
|
zkey := C.CString(tapKey)
|
||||||
defer C.free(unsafe.Pointer(zkey))
|
defer C.free(unsafe.Pointer(zkey))
|
||||||
|
|
||||||
|
// args not key delay
|
||||||
if len(args) > 2 && (reflect.TypeOf(args[2]) != reflect.TypeOf(num)) {
|
if len(args) > 2 && (reflect.TypeOf(args[2]) != reflect.TypeOf(num)) {
|
||||||
num = len(args)
|
num = len(args)
|
||||||
for i := 0; i < num; i++ {
|
for i := 0; i < num; i++ {
|
||||||
@ -685,6 +693,7 @@ func KeyTap(tapKey string, args ...interface{}) string {
|
|||||||
return C.GoString(str)
|
return C.GoString(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// key delay
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
if reflect.TypeOf(args[0]) == reflect.TypeOf(keyArr) {
|
if reflect.TypeOf(args[0]) == reflect.TypeOf(keyArr) {
|
||||||
|
|
||||||
@ -736,12 +745,29 @@ func KeyTap(tapKey string, args ...interface{}) string {
|
|||||||
return C.GoString(str)
|
return C.GoString(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyToggle toggle the keyboard
|
// KeyToggle toggle the keyboard, if there not have args default is "down"
|
||||||
//
|
//
|
||||||
// See keys:
|
// See keys:
|
||||||
// https://github.com/go-vgo/robotgo/blob/master/docs/keys.md
|
// 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 {
|
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)
|
ckey := C.CString(key)
|
||||||
defer C.free(unsafe.Pointer(ckey))
|
defer C.free(unsafe.Pointer(ckey))
|
||||||
|
|
||||||
@ -757,6 +783,7 @@ func KeyToggle(key string, args ...string) string {
|
|||||||
return C.GoString(str)
|
return C.GoString(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use key_toggle()
|
||||||
var (
|
var (
|
||||||
down, mKey, mKeyT = "null", "null", "null"
|
down, mKey, mKeyT = "null", "null", "null"
|
||||||
// keyDelay = 10
|
// keyDelay = 10
|
||||||
|
Loading…
Reference in New Issue
Block a user