optimize code and update godoc

This commit is contained in:
vcaesar 2018-04-22 23:34:04 +08:00
parent bfb57c6be9
commit f5216aa9dc

View File

@ -713,13 +713,19 @@ func inputUTF(str string) {
defer C.free(unsafe.Pointer(cstr)) defer C.free(unsafe.Pointer(cstr))
} }
// TypeStr type string, support UTF-8 // TypeStr send a string, support UTF-8
func TypeStr(str string) { // TypeStr(string: The string to send, float64: microsleep time)
func TypeStr(str string, args ...float64) {
var tm = 7.0
if len(args) > 0 {
tm = args[0]
}
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
strUc := toUC(str) strUc := toUC(str)
for i := 0; i < len(strUc); i++ { for i := 0; i < len(strUc); i++ {
inputUTF(strUc[i]) inputUTF(strUc[i])
MicroSleep(7) MicroSleep(tm)
} }
} else { } else {
for i := 0; i < len([]rune(str)); i++ { for i := 0; i < len([]rune(str)); i++ {
@ -735,14 +741,16 @@ func UnicodeType(str uint32) {
C.unicodeType(cstr) C.unicodeType(cstr)
} }
// TypeString type string, support unicode // TypeString send a string, support unicode
func TypeString(x string) { // TypeStr(string: The string to send)
cx := C.CString(x) func TypeString(str string) {
C.type_string(cx) cstr := C.CString(str)
defer C.free(unsafe.Pointer(cx)) C.type_string(cstr)
defer C.free(unsafe.Pointer(cstr))
} }
// PasteStr paste string, support UTF-8 // PasteStr paste a string, support UTF-8
func PasteStr(str string) { func PasteStr(str string) {
clipboard.WriteAll(str) clipboard.WriteAll(str)
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
@ -753,29 +761,31 @@ func PasteStr(str string) {
} }
// TypeStrDelay type string delayed // TypeStrDelay type string delayed
func TypeStrDelay(str string, y int) { func TypeStrDelay(str string, delay int) {
cstr := C.CString(str) cstr := C.CString(str)
cy := C.size_t(y) cdelay := C.size_t(delay)
C.type_string_delayed(cstr, cy) C.type_string_delayed(cstr, cdelay)
defer C.free(unsafe.Pointer(cstr)) defer C.free(unsafe.Pointer(cstr))
} }
// TypeStringDelayed type string delayed, Wno-deprecated // TypeStringDelayed type string delayed, Wno-deprecated
func TypeStringDelayed(x string, y int) { func TypeStringDelayed(str string, delay int) {
cx := C.CString(x) cstr := C.CString(str)
cy := C.size_t(y) cdelay := C.size_t(delay)
C.type_string_delayed(cx, cy) C.type_string_delayed(cstr, cdelay)
defer C.free(unsafe.Pointer(cx))
defer C.free(unsafe.Pointer(cstr))
} }
// SetKeyDelay set keyboard delay // SetKeyDelay set keyboard delay
func SetKeyDelay(x int) { func SetKeyDelay(key int) {
C.set_keyboard_delay(C.size_t(x)) C.set_keyboard_delay(C.size_t(key))
} }
// SetKeyboardDelay set keyboard delay, Wno-deprecated // SetKeyboardDelay set keyboard delay, Wno-deprecated
func SetKeyboardDelay(x int) { func SetKeyboardDelay(key int) {
C.set_keyboard_delay(C.size_t(x)) C.set_keyboard_delay(C.size_t(key))
} }
/* /*