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.

postEventFromUser double-letters

Postby LunaRebirth » Sun Sep 10, 2017 2:20 am

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:
cpp 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.
LunaRebirth
 
Posts: 301
Joined: Sun May 11, 2014 12:13 am

Re: postEventFromUser double-letters

Postby CuteAlien » Sun Sep 10, 2017 7:11 pm

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.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8365
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: postEventFromUser double-letters

Postby LunaRebirth » Mon Sep 11, 2017 2:40 am

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
LunaRebirth
 
Posts: 301
Joined: Sun May 11, 2014 12:13 am


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest