Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: need help with virtual keyboard and the erase to left character  (Read 1888 times)

0 Members and 3 Guests are viewing this topic.

Saud

  • Newbie
  • *
  • Posts: 9
    • View Profile
need help with virtual keyboard and the erase to left character
« on: December 14, 2019, 10:09:53 pm »
Hello,
Ive been searching lately for a solution, i havnt found yet, for a problem using Textentered event and android virtual keyboard.

The std::string doesnt seem to recieve over 128 unicode characters, specially arabic letters and the erase to the lift button (U+232B).

I tried using wstring and fonts that support these characters, i even tried using sf::String and convert it to wide string, but the problem persist.

Here is my code, last edited, showing only whats related to my issue:


// after enabling the virtual keyboard

wstring str0;
sf::Text txt0;

if (event.type == sf::Event::TextEntered)
{
                               
        if (str0.size()<=15) str0+=event.text.unicode;
        if (event.text.unicode==L'\n')
        {
                str0.erase(str0.size()-1, 1);
                                       
                                       
                                       
        }
        if (event.text.unicode==L'\u232B')
        {
                                       
                str0.erase(str0.size()-2, 2);
                                       
                                       
        }
                               
        txt0.setString(str0);
                               
                               
}


 

this code works with English letters and the enter button in the virtual keyboard, but it doesnt work with arabic nor the erase to the left character.

Note: im testing this only on Android, using a HUAWEI device with Android 8 OS.
« Last Edit: December 14, 2019, 10:48:45 pm by Saud »

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: need help with virtual keyboard and the erase to left character
« Reply #1 on: December 17, 2019, 01:47:16 pm »
my laptop support arabic alphabet. i tried to generate your error but no avail every things looks work fine from SFML side.

just to clarify things:
does this "erase to left character" means "BackSpace" on the keyboard?

i made minimal example by using `'\b'` and `'\r'` which is working fine as i said before. other wise you have to write your own minimal example which's cause the issue to let the others to test your code and solve the problem.

#include <SFML/Window.hpp>

int main()
{
        sf::Window window({ 640 ,480 }, "test arabic alphabet");

        std::wstring arabic_str;

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                        else if (event.type == sf::Event::TextEntered)
                        {
                                if (event.text.unicode == '\b')  // press backspace
                                {
                                        if (!arabic_str.empty())
                                                arabic_str.pop_back();
                                }
                                else if (event.text.unicode == '\r') // press enter/return
                                {
                                        if (!arabic_str.empty())
                                                arabic_str.pop_back();
                                }
                                else {
                                        arabic_str += event.text.unicode;
                                }
                        }
                }

                window.setTitle(arabic_str);
                window.display();
        }
}
« Last Edit: December 17, 2019, 05:24:12 pm by Mortal »

Saud

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: need help with virtual keyboard and the erase to left character
« Reply #2 on: December 17, 2019, 06:16:01 pm »
Thanx for replying.
Yeh ive tested Arabic characters on laptop keyboard and it works fine, and i even built my own mini keyboard in my mini game using sfml sprites and it worked.

but the problem here is with the virtual keyboard that pops up in mobile phone when you need to write something, sf::Event::Textentered doesnt seem to spot some characters pressed in the virtual keyboard, its like they are never pressed.

The erase to left button in mobile phone does what backspace button do in the pc keyboard but with a different unicode id. this link shows info on erase to lift button.
https://www.fileformat.info/info/unicode/char/232b/index.htm

Note: i use sf::Keyboard::setVirtualKeyboardVisible(true) to let the mobile keyboard pops up in Android mobile phone.
« Last Edit: December 17, 2019, 06:29:09 pm by Saud »

Mortal

  • Sr. Member
  • ****
  • Posts: 284
    • View Profile
Re: need help with virtual keyboard and the erase to left character
« Reply #3 on: December 17, 2019, 06:35:43 pm »
yeah, that's what i suspected too, the erase to left character is a different input entity. now it's clear.

unfortunately, i haven't worked on any mobile platforms yet. soon i'm gonna delve in it.

sorry i can't help much on this issue.