@@ -191,7 +191,7 @@ void tapKey(char c, MMKeyFlags flags)
191
191
}
192
192
193
193
#if defined(IS_MACOSX )
194
- void toggleUnicodeKey (UniChar ch , const bool down )
194
+ void toggleUnicodeKey (unsigned long ch , const bool down )
195
195
{
196
196
/* This function relies on the convenient
197
197
* CGEventKeyboardSetUnicodeString(), which allows us to not have to
@@ -204,16 +204,25 @@ void toggleUnicodeKey(UniChar ch, const bool down)
204
204
return ;
205
205
}
206
206
207
- CGEventKeyboardSetUnicodeString (keyEvent , 1 , & ch );
207
+ if (ch > 0xFFFF ) {
208
+ // encode to utf-16 if necessary
209
+ unsigned short surrogates [] = {
210
+ 0xD800 + ((ch - 0x10000 ) >> 10 ),
211
+ 0xDC00 + (ch & 0x3FF )
212
+ };
213
+
214
+ CGEventKeyboardSetUnicodeString (keyEvent , 2 , & surrogates );
215
+ } else {
216
+ CGEventKeyboardSetUnicodeString (keyEvent , 1 , & ch );
217
+ }
208
218
209
219
CGEventPost (kCGSessionEventTap , keyEvent );
210
220
CFRelease (keyEvent );
211
221
}
212
222
213
223
void toggleUniKey (char c , const bool down )
214
224
{
215
- UniChar ch = (UniChar )c ; /* Convert to unsigned char */
216
- toggleUnicodeKey (ch , down );
225
+ toggleUnicodeKey (c , down );
217
226
}
218
227
#else
219
228
#define toggleUniKey (c , down ) toggleKey(c, down, MOD_NONE)
@@ -227,10 +236,10 @@ static void tapUniKey(char c)
227
236
228
237
void typeString (const char * str )
229
238
{
230
- unsigned long c ;
231
- unsigned long c1 ;
232
- unsigned long c2 ;
233
- unsigned long c3 ;
239
+ unsigned short c ;
240
+ unsigned short c1 ;
241
+ unsigned short c2 ;
242
+ unsigned short c3 ;
234
243
unsigned long n ;
235
244
236
245
while (* str != '\0' ) {
0 commit comments