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.
This commit is contained in:
parent
c91eaceee1
commit
a045278822
2 changed files with 5 additions and 7 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue