ImGui.NET icon indicating copy to clipboard operation
ImGui.NET copied to clipboard

How to use vietnamese keyboard to enter text in Inputtext?

Open dominota opened this issue 5 years ago • 0 comments

I use user graphics library, ImGuiNet in my project with SharpDX and Winforms. I face problem with typing Vietnamese language in Inputtext control. I can display Vietnamese characters on almost ImGuiNet controls (from coding) except Inputtext control by keyboard typing. You can see in image:

z

The text from keyboard typing is wrong. I get haà noôiội but expected result is hà nội. The typing software is Vietnamese keyboard for Windows. In this keyboard software, à = a + f and ộ = o + o + j The code from KeyDown event to update ImGuiNet Input like this:

`[DllImport("user32.dll")] public static extern int ToUnicode(uint virtualKeyCode, uint scanCode, byte[] keyboardState, [Out, MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)] StringBuilder receivingBuffer, int bufferSize, uint flags);

public void UpdateKeyDown(KeyEventArgs e)
    {
        bool IsShiftKeyPressed = false;
        if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
        {
            IsShiftKeyPressed = true;
        }

        var io = ImGui.GetIO();

        if (e.KeyValue < 256)
        {
            io.KeysDown[e.KeyValue] = true;
            io.AddInputCharactersUTF8(GetCharsFromKeys(e.KeyCode, IsShiftKeyPressed)); 
        }

        io.KeyAlt = e.Alt;
        io.KeyCtrl = e.Control;
        io.KeyShift = e.Shift;
    }

static string GetCharsFromKeys(Keys keys, bool isShiftPressed)
    {
        var buf = new StringBuilder(256);
        var keyboardState = new byte[256];
        if (isShiftPressed)
        {
            keyboardState[(int)Keys.ShiftKey] = 0xff;
        }
        ToUnicode((uint)keys, 0, keyboardState, buf, 256, 0);
        return buf.ToString();
    }`

I want to typing vietnamese in Inputtext but i am new with ImGui so i can not figure out how to do. Can you point me some code hint?

Thank you in advance

dominota avatar Jul 08 '20 04:07 dominota