Page 1 of 1

EventTextAccepted not working...

Posted: Sun May 22, 2005 18:40
by Derek
Hey,

I've tried to subscribe a WindowsLook/Editbox named "Input" to an EventTextAccepted, but I can't get it to work. injectKeyDown ( ) seems to be returning false when i hit enter.

Code: Select all

 pConsoleInput->subscribeEvent ( Editbox::EventKeyDown, CWindowEventHandlers::HandleConsoleInput );


Where HandleConsoleInput is:

Code: Select all

 bool CWindowEventHandlers::HandleConsoleInput ( const CEGUI::EventArgs &e )


Like I said, it seems that injectKeyDown is just returning false, and HandleConsoleInput is never executed. I've already tried another event (EventTextChanged) and that worked fine. What else am I doing wrong here?

Also, how do you grab a child window? I have a window named console and it has a child named input. I want to get the Console/Input window, but when I try to use WindowManager::getSingleton().getWindow( "Console/Input" ) the library throws an exception and says that the window doesn't exist.

Thanks,

-Derek

Re: EventTextAccepted not working...

Posted: Sun May 22, 2005 22:23
by spannerman
Are you calling injectKeyDown? For example, in OGRE whenever there is a key pressed event I notify CEGUI of the fact, e.g.

Code: Select all

void MyApp::keyPressed(KeyEvent* e)
{
...
  // do event   injection
  CEGUI::System& cegui = CEGUI::System::getSingleton();
  // key down
  cegui.injectKeyDown(e->getKey());
  // now character
  cegui.injectChar(e->getKeyChar());
...
}


Im not sure about your child input problem. Are you sure your passing in the correct string name?
To get for example a textbox I'd do:

Code: Select all

bool MyApp::handleEditBox(const CEGUI::EventArgs& e)
{
  CEGUI::String boxName = (((const CEGUI::WindowEventArgs&)e).window)->getName();
  Editbox* ebox = (Editbox*)WindowManager::getSingleton().getWindow( boxName );

Re: EventTextAccepted not working...

Posted: Sun May 22, 2005 22:55
by Derek
yes, i'm calling injectKeyDown and Up.


The windows are created through CELayoutEditor.

-Derek

Re: EventTextAccepted not working...

Posted: Mon May 23, 2005 00:13
by Derek
Oh yeah, doesn't seem like arrow keys/backspace are working either...

I'm just sending the keycode in WPARAM from WM_KEYDOWN straight to injectKeyDown. Is this the right way to do it?

-Derek

Re: EventTextAccepted not working...

Posted: Fri May 27, 2005 18:00
by Derek
so does anyone know how I can inject keydown/keyups from WM_messages instead of a dinput device without having to edit the cegui sources?

-Derek

Re: EventTextAccepted not working...

Posted: Sat May 28, 2005 01:59
by Nikon
I'm usually just a broswer of this forum and don't usually reply, but here goes nothing...

Code: Select all

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch (message)
   {
                case WM_KEYDOWN:
      {
         unsigned char key = wParam;
         System::getSingleton().injectChar(key);

         break;
      }
        }
}


This has worked for me without ever needing to use injectKeyDown, although I think you are probably supposed to.

Hope this works

Nikon

P.S. How's MTA:Blue coming along?

Re: EventTextAccepted not working...

Posted: Sat May 28, 2005 09:20
by CrazyEddie
@Derek:
I think the wParam key codes for WM_KEYDOWN are different to the DirectInput key codes, so what you really need is to create a translation lookup table and use that.

Alternatively, you could be very selective about which key up/downs to send (like just shift keys, arrow keys, and return or something) - in which case a simple switch in your WM_KEYDOWN handler would probably suffice.

CE.

Re: EventTextAccepted not working...

Posted: Sat May 28, 2005 16:32
by Derek
It's coming along rather nicely :)

We just went through a major rewrite of the core part of the project and i'm finishing up a steam-style console.

-Derek

Re: EventTextAccepted not working...

Posted: Sat May 28, 2005 16:40
by Derek
Thanks eddie, i'll probably just do the latter.

All i REALLY need is enter, arrow keys, page up, page down, home, etc., so I'll just implement those with a switch case.

Thanks guys,

-Derek

Re: EventTextAccepted not working...

Posted: Sat May 28, 2005 18:02
by Derek
by the way, what is the best thing to use for consoles? I need the text that is echoed to the console to render from the bottom UP, instead of from the top down like it is right now using a multilineeditbox.

-Derek

Re: EventTextAccepted not working...

Posted: Sun May 29, 2005 08:50
by CrazyEddie
Most people use a Listbox for their console output, and make a call to ensure the last line is visible after each output. Though it would still start at the top, so you have a couple of options:

1) Initially pad the output with blank lines, so that the first 'real' line appears at the bottom.

2) Create a customised Listbox for this usage that renders it's items in reverse order.

CE.

Re: EventTextAccepted not working...

Posted: Sun May 29, 2005 17:23
by Derek
Hmmm... i tried to use a listbox earlier but i couldn't see any text. I'd see the scroll bar get smaller when i added things in, but none of the text would show (adding from a ListboxTextItem).

I would do something like

Code: Select all

pListItem = new ListboxItem ( m_pInputWindow->getText ( ) )
pListBox->addItem ( pListItem );


Anything i'm doing wrong? I'm using the windows look.
InputWindow is an Editbox*.



-Derek

Re: EventTextAccepted not working...

Posted: Sun May 29, 2005 22:51
by lindquist
I think you need to set the text colour. I had that problem myself some time ago...