c# - Using SendInput to send unicode characters beyond U+FFFF -


i'm writing onscreen keyboard similar 1 in windows 8. have no problem sending of characters need using win32's sendinput.

the problem when comes new windows 8 emoji's. start @ u+1f600 using segoe ui symbol font.

using spy++ on windows 8 onscreen keyboard following output emoji glyphs.

<00001> 000c064a p wm_keydown nvirtkey:vk_packet crepeat:1 scancode:00 fextended:0 faltdown:0 frepeat:0 fup:0 <00002> 000c064a p wm_char chcharcode:'63' (63) crepeat:1 scancode:00 fextended:0 faltdown:0 frepeat:0 fup:0 <00003> 000c064a p wm_keyup nvirtkey:vk_packet crepeat:1 scancode:00 fextended:0 faltdown:0 frepeat:1 fup:1 <00004> 000c064a p wm_keydown nvirtkey:vk_packet crepeat:1 scancode:00 fextended:0 faltdown:0 frepeat:0 fup:0 <00005> 000c064a p wm_char chcharcode:'63' (63) crepeat:1 scancode:00 fextended:0 faltdown:0 frepeat:0 fup:0 <00006> 000c064a p wm_keyup nvirtkey:vk_packet crepeat:1 scancode:00 fextended:0 faltdown:0 frepeat:1 fup:1 

since produce same output can't see sent identifies unique glyph.

i'm aware sendinput has keyeventf_unicode parameter sending unicode characters. these characters seem in sort of extended unicode page. beyond 16-bit unicode range (u+0000 u+ffff) c# char or short wscan value in input struct can represent.

here sendcharunicode method.

public static void sendcharunicode(char ch) {     win32.input[] input = new win32.input[2];      input[0] = new win32.input();     input[0].type = win32.input_keyboard;     input[0].ki.wvk = 0;     input[0].ki.wscan = (short)ch;     input[0].ki.time = 0;     input[0].ki.dwflags = win32.keyeventf_unicode;     input[0].ki.dwextrainfo = win32.getmessageextrainfo();      input[1] = new win32.input();     input[1].type = win32.input_keyboard;     input[1].ki.wvk = 0;     input[1].ki.wscan = (short)ch;     input[1].ki.time = 0;     input[1].ki.dwflags = win32.keyeventf_unicode | win32.keyeventf_keyup;     input[1].ki.dwextrainfo = win32.getmessageextrainfo();      win32.sendinput(2, input, marshal.sizeof(typeof(win32.input))); } 

how can method modified send unicode character such 😃 (u+1f600)?

i have used api monitor on windows 8 onscreen keyboard , indeed use sendinput. after further investigation have discovered need break utf-32 unicode character down utf-16 surrogate pair eg. 😄 u+1f604 becomes [u+d83d u+de04]. if send d83d de04 can send u+1f604.

here working method:

public static void sendcharunicode(int utf32) {     string unicodestring = char.convertfromutf32(utf32);     win32.input[] input = new win32.input[unicodestring.length];      (int = 0; < input.length; i++)     {         input[i] = new win32.input();         input[i].type = win32.input_keyboard;         input[i].ki.wvk = 0;         input[i].ki.wscan = (short)unicodestring[i];         input[i].ki.time = 0;         input[i].ki.dwflags = win32.keyeventf_unicode;         input[i].ki.dwextrainfo = intptr.zero;     }      win32.sendinput((uint)input.length, input, marshal.sizeof(typeof(win32.input))); } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -