Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cultural Unicode text cannot be typed into Textbox. #13190

Closed
dieuminhs opened this issue Oct 10, 2023 · 23 comments · Fixed by #15394
Closed

Cultural Unicode text cannot be typed into Textbox. #13190

dieuminhs opened this issue Oct 10, 2023 · 23 comments · Fixed by #15394
Assignees
Labels

Comments

@dieuminhs
Copy link
Contributor

Describe the bug

When the Textbox is inputted by typing with Cultural Unicode text, the whole text disappears but it doesn't when the text is copied and pasted.

To Reproduce

Steps to reproduce the behavior:

  1. Create a Textbox.
  2. Type a culture Unicode type of text, for example in my culture: á, é can be created by typing aa and ee using keyboard tools or Windows display language.

Expected behavior

The "á, é" text should be display normally instead of blank.

Screenshots

Expected result (Works on WPF).
image

Environment

  • OS: Windows 11
  • Avalonia-Version: 11.0.4

Additional context

  • I had already used another font family like Arial Regular but the result is still the same.
@dieuminhs dieuminhs added the bug label Oct 10, 2023
@timunie
Copy link
Contributor

timunie commented Oct 10, 2023

for example in my culture

what is your culture explicitly?

@timunie
Copy link
Contributor

timunie commented Oct 10, 2023

What are keyboard tools? do you have a screen record for us?

@dieuminhs
Copy link
Contributor Author

dieuminhs commented Oct 10, 2023

for example in my culture

what is your culture explicitly?

My culture is Vietnamese (vi-vn)

What are keyboard tools? do you have a screen record for us?

The tool i'm using is this one: https://evkeyvn.com/
And here's the config of the tools:

image

It seems that the error only occurs when i'm using the tools, not by using Windows Cultural display language. But it still works in WPF apps.

Here's the recording

2023-10-10.13-12-25.mp4

@Gillibald Gillibald self-assigned this Oct 10, 2023
@timunie
Copy link
Contributor

timunie commented Oct 10, 2023

Thank you 🙏

Our text export will have a look once he finds the time to do.

@sloweyyy
Copy link

I am encountering the same issue with Vietnamese characters in the TextBox control. When typing using a keyboard tool like evkeyvn.com, the text disappears, which is not the case when pasting text directly. This issue is impacting the usability of the application for Vietnamese users. Looking forward to a resolution or any suggested workarounds.

@Gillibald
Copy link
Contributor

The issue is such a tool isn't translated into English and I do not know how to use it.

@dieuminhs
Copy link
Contributor Author

dieuminhs commented Nov 28, 2023

The issue is such a tool isn't translated into English and I do not know how to use it.

Here is the picture of the configuration.
image
When enabled, the icon will be shown like below.
image
You can type Vietnamese cultural text easily by type a then type s, the result should be 'á', or a then type r, the result should be 'ả'.
AvaloniaUI makes the text disappears after the s is typed instead of showing 'á'.

@timunie
Copy link
Contributor

timunie commented Nov 28, 2023

@dieuminhs maybe you can try to help us supporting this? So you may try to adjust the Avalonia source as needed to make it work. For reference check out the PRs that added other keyboard support https://github.com/AvaloniaUI/Avalonia/pulls?q=is%3Apr+ime

@Gillibald
Copy link
Contributor

I think that the app simulates key presses instead of implementing some proper input method

@dieuminhs
Copy link
Contributor Author

I think that the app simulates key presses instead of implementing some proper input method

I don't know how the app works but it's working fine in WPF so i think there must be something buggy in AvaloniaUI.

@dieuminhs
Copy link
Contributor Author

@dieuminhs maybe you can try to help us supporting this? So you may try to adjust the Avalonia source as needed to make it work. For reference check out the PRs that added other keyboard support https://github.com/AvaloniaUI/Avalonia/pulls?q=is%3Apr+ime

@dieuminhs maybe you can try to help us supporting this? So you may try to adjust the Avalonia source as needed to make it work. For reference check out the PRs that added other keyboard support https://github.com/AvaloniaUI/Avalonia/pulls?q=is%3Apr+ime

It's kinda advanced for me haha, but i'll check it out.

@dieuminhs
Copy link
Contributor Author

Hi @timunie , it seems like everytime a special cultural character is entered (by typing), the WndProcMessageHandler only receives backspace character. So I wanna ask if there is a way to see what is passed to the delegate in the below picture?

image

@timunie
Copy link
Contributor

timunie commented Jan 16, 2024

adding @Gillibald here as it is far beyond my knowledge tbh.

@workgroupengineering
Copy link
Contributor

Hi @timunie , it seems like everytime a special cultural character is entered (by typing), the WndProcMessageHandler only receives backspace character. So I wanna ask if there is a way to see what is passed to the delegate in the below picture?

image

see

protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)

@dieuminhs
Copy link
Contributor Author

Hi @timunie , it seems like everytime a special cultural character is entered (by typing), the WndProcMessageHandler only receives backspace character. So I wanna ask if there is a way to see what is passed to the delegate in the below picture?
image

see

protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)

It's not this one, what i mean is AppWndProc is called by WndProc and WndProc is called by WndProcMessageHandler which is assigned to _wndProcDelegate, so i wanna know where will _wndProcDelegate be called, thanks.

@dieuminhs
Copy link
Contributor Author

@Gillibald I've found the way our cultural tool works, in order to write a cultural character for example á (typing 's' after 'a'), the tool simulate a backspace to delete 'a', then it will perform a SendInput function (winuser.h) using the below input (The keycode is the int value of cultural custom map table. I wonder if these procedures is allowed by Avalonia?
image
If you need, i can provide the source of the tool. Thanks in advance.

@Gillibald
Copy link
Contributor

Gillibald commented Jan 17, 2024

Text input is handled via WM_KEYDOWN, WM_KEYUP and WM_CHAR
The actual text input should always produce a WM_CHAR message

https://github.com/AvaloniaUI/Avalonia/blob/master/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs#L177C45-L177C45

Make sure always to produce key_up and key_down

Unicode text can be sent via KEYEVENTF_UNICODE

Update: It seems this is the most ideal way of sending emulated key events:
https://stackoverflow.com/a/67937018
It uses scancodes so there is no difference to a physical keyboard

@dieuminhs
Copy link
Contributor Author

dieuminhs commented Jan 18, 2024

Text input is handled via WM_KEYDOWN, WM_KEYUP and WM_CHAR The actual text input should always produce a WM_CHAR message

https://github.com/AvaloniaUI/Avalonia/blob/master/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs#L177C45-L177C45

Make sure always to produce key_up and key_down

Unicode text can be sent via KEYEVENTF_UNICODE

Update: It seems this is the most ideal way of sending emulated key events: https://stackoverflow.com/a/67937018 It uses scancodes so there is no difference to a physical keyboard

It seems like when the cultural character is not parsable from Virtual Key or Physical Key, but it can be retrieved correctly by the GetKeySymbol method, is there a way to resolve this ?

image

@bcnghia
Copy link

bcnghia commented Apr 12, 2024

Hello, I am also a Vietnamese user and currently I am having the same error. I don't know if you have fixed this error yet. If you have successfully fixed it, please guide me. @dieuminhs

@dieuminhs
Copy link
Contributor Author

dieuminhs commented Apr 13, 2024

Hello, I am also a Vietnamese user and currently I am having the same error. I don't know if you have fixed this error yet. If you have successfully fixed it, please guide me. @dieuminhs

I've found 2 workarounds currently,

  1. Using the clipboard option to send key in cultural tools.
    image

  2. Build a custom Avalonia that override the RawKeyEvent method.
    Before
    image

After
image

The method belongs to WindowImpl.AppWndProc.cs source file in Avalonia.Win32 Project.
I don't know if this alteration will affect others but worth a try.

@Gillibald
Copy link
Contributor

I think we can add that fix to Avalonia because it seems to be the right thing to do

@sloweyyy
Copy link

Nice, it works for me @dieuminhs

@dieuminhs
Copy link
Contributor Author

I think we can add that fix to Avalonia because it seems to be the right thing to do

Ok, i will create a pull request for it, thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants