Prev: Unicode Labels
Next: EM_CHARFROMPOS in RichEdit
From: Karl E. Peterson on 29 Jan 2009 14:23 Is there anyone out there who wants to use Unicode characters with the SendInput function? I had someone ask me recently if I could update my SendKeys replacement sample (http://vb.mvps.org/samples/SendInput) such that they could also send Unicode characters with it. I tweaked it a bit, and she reported it was now working for her, but I'm not sure it was a most-representative user doing the testing. I have no need (or interest) in using that functionality myself, so I'm not sure if my assumptions were good for others. Anyone wanna have a crack at it? -- ..NET: It's About Trust! http://vfred.mvps.org
From: expvb on 29 Jan 2009 17:15 "Karl E. Peterson" <karl(a)mvps.org> wrote in message news:OpVyRckgJHA.4572(a)TK2MSFTNGP04.phx.gbl... > Is there anyone out there who wants to use Unicode characters with the > SendInput function? I had someone ask me recently if I could update my > SendKeys replacement sample (http://vb.mvps.org/samples/SendInput) such > that they could also send Unicode characters with it. I tweaked it a bit, > and she reported it was now working for her, but I'm not sure it was a > most-representative user doing the testing. I have no need (or interest) > in using that functionality myself, so I'm not sure if my assumptions were > good for others. Anyone wanna have a crack at it? The sample is unchanged since I downloaded it about 2 months ago(no binary differences).
From: Karl E. Peterson on 29 Jan 2009 17:46 expvb wrote: > "Karl E. Peterson" <karl(a)mvps.org> wrote ... >> Is there anyone out there who wants to use Unicode characters with the >> SendInput function? I had someone ask me recently if I could update my >> SendKeys replacement sample (http://vb.mvps.org/samples/SendInput) such >> that they could also send Unicode characters with it. I tweaked it a bit, >> and she reported it was now working for her, but I'm not sure it was a >> most-representative user doing the testing. I have no need (or interest) >> in using that functionality myself, so I'm not sure if my assumptions were >> good for others. Anyone wanna have a crack at it? > > The sample is unchanged since I downloaded it about 2 months ago(no binary > differences). Sorry! I should've been more clear. I was seeking input *before* uploading for all. <g> Here's the updated code: http://vb.mvps.org/samples/raw/MSendInput.bas.txt (Note to Archive: Not sure that'll stay there, after this thread dies down.) -- ..NET: It's About Trust! http://vfred.mvps.org
From: Karl E. Peterson on 29 Jan 2009 17:52 expvb wrote: > "Karl E. Peterson" <karl(a)mvps.org> wrote ... >> Is there anyone out there who wants to use Unicode characters with the >> SendInput function? I had someone ask me recently if I could update my >> SendKeys replacement sample (http://vb.mvps.org/samples/SendInput) such >> that they could also send Unicode characters with it. I tweaked it a bit, >> and she reported it was now working for her, but I'm not sure it was a >> most-representative user doing the testing. I have no need (or interest) >> in using that functionality myself, so I'm not sure if my assumptions were >> good for others. Anyone wanna have a crack at it? > > The sample is unchanged since I downloaded it about 2 months ago(no binary > differences). Key points I'm wondering about are, 1) Is a simple 0-255 check sufficient recognition for "Unicode" characters, where the input variable 'this' is a single character from a longer string? Private Sub ProcessChar(this As String) Dim code As Integer Dim vk As Integer Dim capped As Boolean ' Determine whether we need to treat as Unicode. code = AscW(this) If code >= 0 And code < 256 Then 'ascii ' Add input events for single character, taking capitalization ' into account. HiByte will contain the shift state, and LoByte ' will contain the key code. vk = VkKeyScan(Asc(this)) capped = CBool(ByteHi(vk) And 1) vk = ByteLo(vk) Call StuffBuffer(vk, capped) Else 'unicode Call StuffBufferW(code) End If End Sub 2) If it's Unicode, that means we skip all the Shiftkey processing, and instead just do this, right? Private Sub StuffBufferW(ByVal CharCode As Integer) ' Unicode is relatively simple, in this context?! ' Press and release this key. With m_Events(m_EvtPtr) .wVK = 0 .wScan = CharCode .dwFlags = KEYEVENTF_UNICODE End With m_EvtPtr = m_EvtPtr + 1 With m_Events(m_EvtPtr) .wVK = 0 .wScan = CharCode .dwFlags = KEYEVENTF_UNICODE Or KEYEVENTF_KEYUP End With m_EvtPtr = m_EvtPtr + 1 End Sub 3) What else I've overlooked? <g> Thanks... Karl -- ..NET: It's About Trust! http://vfred.mvps.org
From: expvb on 29 Jan 2009 19:09
"Karl E. Peterson" <karl(a)mvps.org> wrote in message news:OzYw1QmgJHA.2092(a)TK2MSFTNGP05.phx.gbl... > Key points I'm wondering about are, > > 1) Is a simple 0-255 check sufficient recognition for "Unicode" > characters, where the input variable 'this' is a single character from a > longer string? I am by no means an expert in this area, but here is what I know. Char codes from 128 to 255 have special meaning, depending on whether you are using ANSI or Unicode. In Unicode, their meaning is fixed regardless of Code Page. They refer to Latin-1 Supplement, so for instance char code 169 is always the copyright symbol. In ANSI, char codes from 128 to 255 have no meaning without the associated Code Page. So when someone says char code 169 is the copyright symbol, he or she is wrong. They must also say what Code Page they are talking about. So you have to add a Unicode flag to treat char codes 128 to 255 properly. See these articles: http://en.wikipedia.org/wiki/Basic_Multilingual_Plane http://en.wikipedia.org/wiki/Unicode > 2) If it's Unicode, that means we skip all the Shiftkey processing, and > instead just do this, right? It seems so. It seems that in order to get keyboard scan codes, keyboard layout and support for specific code pages has to be loaded(In the Control Panel perhaps), so it doesn't seem possible to get scan codes for every possible Unicode char. You can however send a Unicode char by sending WM_CHAR using the W version of SendMessage after checking that the window is a Unicode window by calling IsWindowUnicode(). > 3) What else I've overlooked? <g> Checking that the OS is Windows 2000 before using KEYEVENTF_UNICODE flag, and that the minimum required OS is Windows 98 because that is when SendInput() was introduced. |