This project is read-only.

Send special characters to TextBox

Jan 10, 2012 at 9:21 PM
Edited Jan 11, 2012 at 8:05 AM

My application has to support all the characters in ISO 8859-2 encoding, for example:










But it seems that White doesn't support all of these characters. Example:

        myWindow.myTextBox.Text = "ŕáâăäĺćçčéęëěíîď" //This inserts only characters "ćč" into the TextBox.

        myWindow.myTextBox.Text = "ąłľśšşťźžż" //This inserts only characters "kšž" into the TextBox.

I am using Windows XP (in Slovenian language) and Visual Studio 2005, .NET Framework 2.0 (legacy application... ). Are there any additional configurations, that I have to set?


PS - I initially posted this in "Issue Tracker" but it's probably better suited for Discussions section, sorry for double posting.

Jan 20, 2012 at 8:30 AM
Edited Jan 20, 2012 at 10:59 AM

I found out that in the background the SendInput method of USER32.DLL library is called, thanks to

My code:

Imports System.Runtime.InteropServices
Imports White.Core.UIItems

Namespace Utils
    Public Class Keyboard
        <DllImport("USER32.dll", CharSet:=CharSet.Unicode)> _
        Private Shared Function SendInput(ByVal numberOfInputs As UInt32, ByVal input As INPUT(), ByVal sizeOfInputStructure As Int32) As UInt32
        End Function

        <StructLayout(LayoutKind.Sequential, Size:=24)> _
        Structure KEYBDINPUT
            Public Vk As Int16
            Public Scan As Int16
            Public Flags As Int32
            Public Time As Int32
            Public ExtraInfo As Int32
        End Structure

        <StructLayout(LayoutKind.Explicit)> _
        Private Structure INPUT
            <FieldOffset(0)> _
            Public Type As Integer
            <FieldOffset(4)> _
            Public ki As KEYBDINPUT
        End Structure

        Public Shared Sub SendTextToUIItem(ByVal uiItem As UIItem, ByVal text As String)

            Dim chars As Char() = text.ToCharArray()

            For i As Integer = 0 To chars.Length - 1
                Dim unicode As UInt16 = AscW(chars(i))

                Dim down As New INPUT()
                down.Type = 1
       = 0
       = unicode
       = 0
       = &H4
       = 0

                Dim up As New INPUT()
                up.Type = 1
       = 0
       = unicode
       = 0
       = &H4
       = 0

                Dim input As INPUT() = New INPUT(1) {}
                input(0) = down
                input(1) = up
                SendInput(1, input, Marshal.SizeOf(GetType(INPUT)))
        End Sub
    End Class
End Namespace
And in the tests:
Utils.Keyboard.SendTextToUIItem(myWindow.myTextBox, "ðñòóôõö÷øùúûüýþÿ")
Jan 20, 2012 at 9:54 AM
Edited Jan 20, 2012 at 11:01 AM

I had problems if the word had same characters, for instance:

Utils.Keyboard.SendTextToUIItem(myWindow.myTextBox, "Jeff") ' This writes Jef instead of Jeff

If I add Thread.Sleep(1) just below the SendInput(1, input, Marshal.SizeOf(GetType(INPUT))) statement in SendTextToIUItem method, then it works fine...

Utils.Keyboard.SendTextToUIItem(myWindow.myTextBox, "Jeff") ' This writes Jeff

Feb 11, 2012 at 6:36 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Feb 11, 2012 at 6:37 PM

If trapping keyboard events is not an issue then you can try using BulkText method as well