mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-06-01 06:33:56 +00:00
add linux typestr utf support
This commit is contained in:
parent
363c538275
commit
fda0ba08a3
@ -214,6 +214,39 @@ void toggleUnicode(UniChar ch, const bool down)
|
||||
|
||||
#if defined(USE_X11)
|
||||
#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
|
||||
|
||||
// unicode type
|
||||
|
31
robotgo.go
31
robotgo.go
@ -54,6 +54,7 @@ import (
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unsafe"
|
||||
@ -691,11 +692,35 @@ func CharCodeAt(s string, n int) rune {
|
||||
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
|
||||
}
|
||||
|
||||
// TypeStr type string, support UTF-8
|
||||
func TypeStr(str string) {
|
||||
for i := 0; i < len([]rune(str)); i++ {
|
||||
ustr := uint32(CharCodeAt(str, i))
|
||||
UnicodeType(ustr)
|
||||
if runtime.GOOS == "linux" {
|
||||
strUc := toUc(str)
|
||||
for i := 0; i < len(strUc); i++ {
|
||||
cstr := C.CString(strUc[i])
|
||||
C.input_utf(cstr)
|
||||
|
||||
defer C.free(unsafe.Pointer(cstr))
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < len([]rune(str)); i++ {
|
||||
ustr := uint32(CharCodeAt(str, i))
|
||||
UnicodeType(ustr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user