Commit a0452788 authored by Weixuan Xiao's avatar Weixuan Xiao
Browse files

Fix and improve unicode input on macOS and Windows

Unicode text input from remote devices gives random texts because the plugin mistook the text encoding. Insert a Unicode 16 bits character each time instead of a UTF-8 character.

The API accepts the `UniChar` Unicode characters:

```c
void CGEventKeyboardSetUnicodeString(CGEventRef event, UniCharCount stringLength, const UniChar *unicodeString);
```

from https://developer.apple.com/documentation/coregraphics/1456028-cgeventkeyboardsetunicodestring.
parent c91eacee
Pipeline #169367 passed with stage
in 6 minutes and 36 seconds
......@@ -178,16 +178,14 @@ bool MacOSRemoteInput::handlePacket(const NetworkPacket& np)
CFRelease(specialKeyDownEvent);
CFRelease(specialKeyUpEvent);
} else {
for (int i=0;i<key.length();i++) {
QByteArray utf8 = QString(key.at(i)).toUtf8();
NSData *data = utf8.toNSData(); // Will be autoreleased
const UniChar* const unicharData = (const UniChar*)data.bytes;
for (int i = 0; i < key.length(); i++) {
const UniChar unicharData = (const UniChar)key.at(i).unicode();
CGEventRef event = CGEventCreateKeyboardEvent(NULL, 0, true);
CGEventKeyboardSetUnicodeString(event, utf8.length(), unicharData);
CGEventKeyboardSetUnicodeString(event, 1, &unicharData);
CGEventPost(kCGSessionEventTap, event);
CFRelease(event);
}
......
......@@ -159,7 +159,7 @@ bool WindowsRemoteInput::handlePacket(const NetworkPacket& np)
} else {
for (int i=0;i<key.length();i++) {
wchar_t inputChar = *QString(key.at(i)).utf16();
wchar_t inputChar = (wchar_t)key.at(i).unicode();
short inputVk = VkKeyScanExW(inputChar, GetKeyboardLayout(0));
if(inputVk != -1) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment