mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-06 08:43:56 +00:00
Merge pull request #130 from go-vgo/dev
add linux type string utf-8 support
This commit is contained in:
commit
dabec28f14
@ -214,6 +214,39 @@ void toggleUnicode(UniChar ch, const bool down)
|
|||||||
|
|
||||||
#if defined(USE_X11)
|
#if defined(USE_X11)
|
||||||
#define toggleUniKey(c, down) toggleKey(c, down, MOD_NONE)
|
#define toggleUniKey(c, down) toggleKey(c, down, MOD_NONE)
|
||||||
|
|
||||||
|
int input_utf(const char *utf) {
|
||||||
|
Display *dpy;
|
||||||
|
dpy = XOpenDisplay(NULL);
|
||||||
|
|
||||||
|
KeySym sym = XStringToKeysym(utf);
|
||||||
|
// KeySym sym = XKeycodeToKeysym(dpy, utf);
|
||||||
|
|
||||||
|
int min, max, numcodes;
|
||||||
|
XDisplayKeycodes(dpy, &min, &max);
|
||||||
|
KeySym *keysym;
|
||||||
|
keysym = XGetKeyboardMapping(dpy, min,max-min+1, &numcodes);
|
||||||
|
keysym[(max-min-1)*numcodes]=sym;
|
||||||
|
XChangeKeyboardMapping(dpy, min, numcodes, keysym, (max-min));
|
||||||
|
XFree(keysym);
|
||||||
|
XFlush(dpy);
|
||||||
|
|
||||||
|
KeyCode code = XKeysymToKeycode(dpy, sym);
|
||||||
|
|
||||||
|
XTestFakeKeyEvent(dpy, code, True, 1);
|
||||||
|
XTestFakeKeyEvent(dpy, code, False, 1);
|
||||||
|
|
||||||
|
XFlush(dpy);
|
||||||
|
|
||||||
|
XCloseDisplay(dpy);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if !defined(USE_X11)
|
||||||
|
int input_utf(const char *utf){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// unicode type
|
// unicode type
|
||||||
|
36
robotgo.go
36
robotgo.go
@ -54,6 +54,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@ -691,11 +692,40 @@ func CharCodeAt(s string, n int) rune {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toUc(text string) []string {
|
||||||
|
var uc []string
|
||||||
|
|
||||||
|
textQuoted := strconv.QuoteToASCII(text)
|
||||||
|
textUnquoted := textQuoted[1 : len(textQuoted)-1]
|
||||||
|
|
||||||
|
sUnicodev := strings.Split(textUnquoted, "\\u")
|
||||||
|
for i := 1; i < len(sUnicodev); i++ {
|
||||||
|
uc = append(uc, "U"+sUnicodev[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return uc
|
||||||
|
}
|
||||||
|
|
||||||
|
func inputUtf(str string) {
|
||||||
|
cstr := C.CString(str)
|
||||||
|
C.input_utf(cstr)
|
||||||
|
|
||||||
|
defer C.free(unsafe.Pointer(cstr))
|
||||||
|
}
|
||||||
|
|
||||||
// TypeStr type string, support UTF-8
|
// TypeStr type string, support UTF-8
|
||||||
func TypeStr(str string) {
|
func TypeStr(str string) {
|
||||||
for i := 0; i < len([]rune(str)); i++ {
|
if runtime.GOOS == "linux" {
|
||||||
ustr := uint32(CharCodeAt(str, i))
|
strUc := toUc(str)
|
||||||
UnicodeType(ustr)
|
for i := 0; i < len(strUc); i++ {
|
||||||
|
inputUtf(strUc[i])
|
||||||
|
MicroSleep(7)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i := 0; i < len([]rune(str)); i++ {
|
||||||
|
ustr := uint32(CharCodeAt(str, i))
|
||||||
|
UnicodeType(ustr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user