Update: update godoc and fixed typo

This commit is contained in:
vcaesar 2022-09-14 15:23:09 -07:00
parent e9b5a9251e
commit c3cda41c2d
2 changed files with 17 additions and 15 deletions

View File

@ -519,9 +519,9 @@ Some discussions and questions, please see [issues/228](https://github.com/go-vg
## Plans ## Plans
- Refactor some C code to Go (such as x11, windows) - Refactor some C code to Go (such as x11, windows)
- Better multiscreen support - Better multiscreen support
- Waylad supports - Wayland support
- Update Window Handle - Update Window Handle
- Try support Android and IOS - Try to support Android and IOS
## Contributors ## Contributors

28
key.go
View File

@ -201,7 +201,7 @@ const (
LightsKbdDown = "lights_kbd_down" LightsKbdDown = "lights_kbd_down"
) )
// keyNames define MMKeyCode map // keyNames define a map of key names to MMKeyCode
var keyNames = map[string]C.MMKeyCode{ var keyNames = map[string]C.MMKeyCode{
"backspace": C.K_BACKSPACE, "backspace": C.K_BACKSPACE,
"delete": C.K_DELETE, "delete": C.K_DELETE,
@ -441,7 +441,7 @@ func keyToggles(k string, keyArr []string, pid int) error {
*/ */
// ToInterfaces []string to []interface{} // ToInterfaces convert []string to []interface{}
func ToInterfaces(fields []string) []interface{} { func ToInterfaces(fields []string) []interface{} {
res := make([]interface{}, 0, len(fields)) res := make([]interface{}, 0, len(fields))
for _, s := range fields { for _, s := range fields {
@ -450,7 +450,7 @@ func ToInterfaces(fields []string) []interface{} {
return res return res
} }
// ToStrings []interface{} to []string // ToStrings convert []interface{} to []string
func ToStrings(fields []interface{}) []string { func ToStrings(fields []interface{}) []string {
res := make([]string, 0, len(fields)) res := make([]string, 0, len(fields))
for _, s := range fields { for _, s := range fields {
@ -467,19 +467,20 @@ func toErr(str *C.char) error {
return errors.New(gstr) return errors.New(gstr)
} }
// KeyTap tap the keyboard code; // KeyTap taps the keyboard code;
// //
// 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: // Examples:
//
// robotgo.KeySleep = 100 // 100 millisecond // robotgo.KeySleep = 100 // 100 millisecond
// robotgo.KeyTap("a") // robotgo.KeyTap("a")
// robotgo.KeyTap("i", "alt", "command") // robotgo.KeyTap("i", "alt", "command")
// //
// arr := []string{"alt", "command"} // arr := []string{"alt", "command"}
// robotgo.KeyTap("i", arr) // robotgo.KeyTap("i", arr)
//
func KeyTap(key string, args ...interface{}) error { func KeyTap(key string, args ...interface{}) error {
var keyArr []string var keyArr []string
@ -512,17 +513,18 @@ func KeyTap(key string, args ...interface{}) error {
return keyTaps(key, keyArr, pid) return keyTaps(key, keyArr, pid)
} }
// KeyToggle toggle the keyboard, if there not have args default is "down" // KeyToggle toggles 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: // Examples:
//
// robotgo.KeyToggle("a") // robotgo.KeyToggle("a")
// robotgo.KeyToggle("a", "up") // robotgo.KeyToggle("a", "up")
// //
// robotgo.KeyToggle("a", "up", "alt", "cmd") // robotgo.KeyToggle("a", "up", "alt", "cmd")
//
func KeyToggle(key string, args ...interface{}) error { func KeyToggle(key string, args ...interface{}) error {
if len(key) > 0 && unicode.IsUpper([]rune(key)[0]) { if len(key) > 0 && unicode.IsUpper([]rune(key)[0]) {
@ -633,13 +635,13 @@ func inputUTF(str string) {
C.free(unsafe.Pointer(cstr)) C.free(unsafe.Pointer(cstr))
} }
// TypeStr send a string, supported UTF-8 // TypeStr send a string (supported UTF-8)
// //
// robotgo.TypeStr(string: "The string to send", int: pid, "milli_sleep time", "x11 option") // robotgo.TypeStr(string: "The string to send", int: pid, "milli_sleep time", "x11 option")
// //
// Examples: // Examples:
// robotgo.TypeStr("abc@123, Hi galaxy, こんにちは")
// //
// robotgo.TypeStr("abc@123, Hi galaxy, こんにちは")
func TypeStr(str string, args ...int) { func TypeStr(str string, args ...int) {
var tm, tm1 = 0, 7 var tm, tm1 = 0, 7
@ -681,7 +683,7 @@ func TypeStr(str string, args ...int) {
MilliSleep(KeySleep) MilliSleep(KeySleep)
} }
// PasteStr paste a string, support UTF-8, // PasteStr paste a string (support UTF-8),
// write the string to clipboard and tap `cmd + v` // write the string to clipboard and tap `cmd + v`
func PasteStr(str string) error { func PasteStr(str string) error {
err := clipboard.WriteAll(str) err := clipboard.WriteAll(str)
@ -696,7 +698,7 @@ func PasteStr(str string) error {
return KeyTap("v", "control") return KeyTap("v", "control")
} }
// TypeStrDelay type string delayed // TypeStrDelay type string with delayed
func TypeStrDelay(str string, delay int) { func TypeStrDelay(str string, delay int) {
TypeStr(str) TypeStr(str)
MilliSleep(delay) MilliSleep(delay)
@ -704,7 +706,7 @@ func TypeStrDelay(str string, delay int) {
// Deprecated: use the TypeStr(), // Deprecated: use the TypeStr(),
// //
// TypeStringDelayed type string delayed, Wno-deprecated // # TypeStringDelayed type string delayed, Wno-deprecated
// //
// This function will be removed in version v1.0.0 // This function will be removed in version v1.0.0
func TypeStringDelayed(str string, delay int) { func TypeStringDelayed(str string, delay int) {
@ -712,7 +714,7 @@ func TypeStringDelayed(str string, delay int) {
TypeStrDelay(str, delay) TypeStrDelay(str, delay)
} }
// SetDelay set the key and mouse delay // SetDelay sets the key and mouse delay
func SetDelay(d ...int) { func SetDelay(d ...int) {
v := 10 v := 10
if len(d) > 0 { if len(d) > 0 {