Page 1 of 1

How can I use the keyboard to control the menu?

Posted: Wed Mar 16, 2011 08:35
by reigys
Hi there,
I am a newbie to CEGUI, and English is not my mother language. Sorry for I my poor English.
I want to use keyboard to control a menu in games. That means, navigate the menu with UP ARROW key and DOWN ARROW key, and confirm with ENTER key. I find this post: http://www.cegui.org.uk/phpBB2/viewtopic.php?t=3321 . But when I add "mGUIManager->injectKeyDown(arg)" to my code, I find this function returns false, and CEGUI cannot handle the key input. I don't why. The code goes as follow:

Code: Select all

bool GameApp::keyPressed( const OIS::KeyEvent &arg )
   {
      if(mGUIManager->injectKeyDown(arg))
         Ogre::LogManager::getSingleton().logMessage("[GameApp]injectKeyDown to CEGUI OK.");
      
      return mStateManager->keyPressed(arg);
   }


and injectKeyDown(arg) is defined as

Code: Select all

inline bool injectKeyDown(OIS::KeyEvent arg)
      {
         return (mpGUISystem->injectKeyDown(arg.key) && mpGUISystem->injectChar(arg.text));
      }


Strangely, all of injectMouseButtonDown(), injectMouseButtonUp() and injectMouseMove() return true, and I can use the mouse in CEGUI.
Any help will be appreciated.

Re: How can I use the keyboard to control the menu?

Posted: Wed Mar 16, 2011 08:43
by reigys
PS: my menu is a layout which consists of a framewindow and four buttons in Vanilla skin. But I think it has nothing to do with my problem. :?

Re: How can I use the keyboard to control the menu?

Posted: Wed Mar 16, 2011 09:45
by Kulik
AFAIK CEGUI doesn't support this out of the box in 0.7 but this is planned for 0.8. You can do this yourself by listening to key up down events in the frame window and activating child buttons accordingly. When the button has focus, you would listen to Enter/Space key event.

Re: How can I use the keyboard to control the menu?

Posted: Wed Mar 16, 2011 20:49
by Jamarr
reigys, there is an article on the wiki that may help: Tab Order. Note I have never used this, and if it works may need to be modified to work with v0.7. Make sure you search the wiki and forums before asking help; this helps avoid clutter on the forums. And please post in the appropriate sub-forum next time (this should be in Beginners Help) as this helps maintain an organized forum. Thanks ;)

Kulik wrote:AFAIK CEGUI doesn't support this out of the box in 0.7 but this is planned for 0.8.


So you are planning on adding a keyboard-focus state in v0.8? If so, what keys will this support by default (tab/shift-tab, arrows, enter/space, home/end, page up/down, esc)? Just curious :)

Re: How can I use the keyboard to control the menu?

Posted: Wed Mar 16, 2011 22:27
by Kulik
Jamarr wrote:So you are planning on adding a keyboard-focus state in v0.8? If so, what keys will this support by default (tab/shift-tab, arrows, enter/space, home/end, page up/down, esc)? Just curious :)


CrazyEddie plans to do that. I imagine it will be configurable.