postEventFromUser double-letters

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

postEventFromUser double-letters

Post by LunaRebirth »

Hello,
I'm working on an Android project and there are some letters (such as :, ;, /, |, *, etc.) that aren't supported by default with the touchscreen.

In order to make them work, I use the following code:

Code: Select all

void MyEventReceiver::SendKeyEvent( irr::EKEY_CODE key_, bool pressedDown_, wchar_t character_)
{
    if ( Game::device && Game::device->getGUIEnvironment() )
    {
        SEvent irrEvent;
        irrEvent.EventType = irr::EET_KEY_INPUT_EVENT;
        irrEvent.KeyInput.PressedDown = pressedDown_;
        irrEvent.KeyInput.Control = false;
        irrEvent.KeyInput.Shift = false;
        irrEvent.KeyInput.Char = character_;
        irrEvent.KeyInput.Key = key_;
 
        //Game::receiver.OnEvent(irrEvent);
        Game::device->getGUIEnvironment()->postEventFromUser(irrEvent);
    }
}
 
bool MyEventReceiver::OnEvent(const SEvent& event)
{
    // ...
    if (event.EventType == irr::EET_KEY_INPUT_EVENT)
    {
    #ifdef _IRR_ANDROID_PLATFORM_
        int SystemKeyCode = event.KeyInput.SystemKeyCode;
        if (SystemKeyCode == 17)
            MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)17,true,'*');
        else if (SystemKeyCode == 75)
            if (event.KeyInput.Shift)
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)75,true,'\"');
            else
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)75,true,'\'');
        else if (SystemKeyCode == 74)
            if (event.KeyInput.Shift)
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)74,true,':');
            else
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)74,true,';');
        else if (SystemKeyCode == 76)
            if (event.KeyInput.Shift)
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)76,true,'?');
            else
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)76,true,'/');
        else if (SystemKeyCode == 73)
            if (event.KeyInput.Shift)
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)73,true,'|');
            else
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)73,true,'\\');
        else if (SystemKeyCode == 70)
            MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)70,true,'=');
        else if (SystemKeyCode == 71)
            if (event.KeyInput.Shift)
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)71,true,'{');
            else
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)71,true,'[');
        else if (SystemKeyCode == 72)
            if (event.KeyInput.Shift)
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)72,true,'}');
            else
                MyEventReceiver::SendKeyEvent((irr::EKEY_CODE)72,true,']');
 
    #endif // _IRR_ANDROID_PLATFORM_
    // ...
}
If I don't use the SendKeyEvent function, the associated character won't appear. But by using it, 2 characters appear instead of one.
I.E entering [ will put [[ in an editbox in Android.

I checked in the event receiver, and one letter is being caught. One for PressedDown and one for !PressedDown.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: postEventFromUser double-letters

Post by CuteAlien »

You always set your pressedDown parameter in SendKeyEvent to true. Try setting it to event.KeyInput.PressedDown instead (seeing that you already created that parameter, I suspect that is what you had planned for it anyway...).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
LunaRebirth
Posts: 386
Joined: Sun May 11, 2014 12:13 am

Re: postEventFromUser double-letters

Post by LunaRebirth »

CuteAlien wrote:You always set your pressedDown parameter in SendKeyEvent to true. Try setting it to event.KeyInput.PressedDown instead (seeing that you already created that parameter, I suspect that is what you had planned for it anyway...).
Your help is always wonderful. Thank you
Post Reply