Page 1 of 1

Frustrated...need help.

Posted: Wed Jul 20, 2005 20:36
by EDarkness
Hello. I'm using Ogre and CEGUI. Right now, I'm trying to setup some buttons that will be selectable with the keyboard and when the user presses "enter/return" it will do something. My problem is all of the tutorials assume you're using a mouse. I have mouse functionality turned off, so I need to get it done with a keyboard. Thing is, I can't figure out how to do it. How do you set the focus of the window manually? I want to set one button as the initial focus, then with the up and down arrows the focus moves to the next button. When they hit "enter/return", an event will happen.

Thing is, I have no idea how to set this up. So I've been staring at my code for the last few days not doing anything. I am in serious need of some guidance, otherwise I'm gonna have to drop this. Anyone have any information that can get me in the right direction? Or maybe even some theory I can use to set this up?

Any help would be greatly appreciated.


-EDarkness

Re: Frustrated...need help.

Posted: Wed Jul 20, 2005 22:11
by lindquist
You would set the focus on a window the activate member function of Window

Code: Select all

Window* w = WindowManager::getSingleton().getWindow("myWindow");
w->activate();


this would ensure that keyboard events would be sent to "myWindow"

if you pressed "down-arrow" with this window active, a "KeyDown" event would be sent to it.

a handler like this could pass on the focus:

Code: Select all

bool myWindowKeyDownHandler(const EventArgs& e)
{
    const KeyEventArgs& ke = (const KeyEventArgs&)e;
    if (ke.scancode == Key::ArrowDown)
    {
        Window* next = WindowManager::getSingleton().getWindow("myNextWindow");
        next->activate();
        return true;
    }
    return false;
}


This is a simple example of what you could do. CEGUI does not currently have any built-in keyboard navigation.

Re: Frustrated...need help.

Posted: Wed Jul 20, 2005 23:29
by EDarkness
Well, that's good to hear. How do you know if the window has focus? Does it light up like it would if you moused over it? Oh, and how to I "fake" mouse events?


-EDarkness

Re: Frustrated...need help.

Posted: Fri Jul 22, 2005 11:33
by CrazyEddie
For the most part there is no visual cue that a widget has input focus. However, buttons have a hover highlight.

What you basically want to do, is respond to the keyboard and move the 'invisible' mouse to the next widget by injecting an appropriate mouse position - by doing this over a series of buttons for example, each button would highlight in turn.

Chris Kang started the work on implementing a proper keyboard interface (there's a patch on the tracker), however I had trouble getting it to function (could have been me though), and Chris has not posted here for a few months.