Page 1 of 1
remove keyboard input focus
Posted: Sun Sep 05, 2004 15:14
by zola
Hi
I haven't found anything about this in the forum so...
How can I remove the keyinput focus from a window?
I have a console where I do some text input. If I press the middle button of the mouse I'd like the focus to disappear from my console.
Now triggering the mouse is easy
but I can't find the method to remove the input focus.
(Btw. the focus doesn't go away either if I just click in an empty place on the screen.)
Any hints are welcome
Regards,
Z
remove keyboard input focus
Posted: Sun Sep 05, 2004 15:37
by zola
I tried this
Code: Select all
void removeKeyFocus(){
CEGUI::Window* ceroot=CEGUI::System::getSingleton().getGUISheet();
ceroot->activate();
}
But it didn't do what I wanted.
remove keyboard input focus
Posted: Sun Sep 05, 2004 15:46
by CrazyEddie
The reason that code does not work is because the active root is
always active anyway
The best kludge is to activate a sibling window or a window on a different ancestoral line. If you have no candidate windows, create any window (DefaultGUISheet would be cheapest), set it's size to 0x0, add it to the same parent as your editbox, then activeate it when you need to move focus away from the editbox (it's a bit wanky I know, but it'll work).
I'll add this on the TODO list, as there's currently no way to achieve this via a simple call.
CE.
remove keyboard input focus
Posted: Mon Sep 06, 2004 10:08
by zola
It works
thank You very much for the fast help
remove keyboard input focus
Posted: Sat Sep 18, 2004 15:42
by CrazyEddie
I have added a new method to the Window base class 'deactivate' that should now allow you to do this more easily
See the front page about another unrelated change that requires you to update your GUILayout.xsd file from the XMLRefSchema directory.
Allow 5 hrs for anon CVS access to sync (snapshots are current).
HTH
CE.
Re: remove keyboard input focus
Posted: Fri Jun 03, 2011 21:24
by Cryst
Hi,
got a very similiar problem. I want the input focus to be removed by a user clicking anywhere on the canvas. Currently the focus is only removed when the user clicks on another CEGUI widget like a StaticText or a button. My first approach was to create an invisible dummy sheet which was with Window::moveToBack() on a per-frame basis pushed to the bottom of the z-order . Didn't work out because it wasn't somehow incompatible with the rest of widgets (buttons stopped working, etc.), maybe because it's just a minor hack
For better comprehension of my problem, have a look at the following picture.
http://imagebin.org/156624Thanks for your help in advance,
Chris
Re: remove keyboard input focus
Posted: Sun Jun 05, 2011 10:46
by Kulik
Hehe, nice thread necromancing.
What is your layout? I
think that if you add a DefaultWindow that takes the entire screen and add your widgets to that, the DefaultWIndow will steal keyboard focus once you click on it. I haven't tested it but I recall this working for me, hopefully I am not wrong.
Re: remove keyboard input focus
Posted: Mon Jun 06, 2011 07:39
by CrazyEddie
Kulik wrote:I haven't tested it but I recall this working for me, hopefully I am not wrong.
I have bad news!
The only way to do this reliably at the moment is to subscribe an event handler and use it to deactivate the editbox. So you might for example use the GlobalEventSet with the event "Window/MouseButtonDown", and test if the target window is an editbox, if not find the active editbox and deactivate. It's not all that elegant, but at the moment I think it's the only reliable way.
CE
Re: remove keyboard input focus
Posted: Mon Jun 06, 2011 11:02
by Cryst
Kulik wrote:I think that if you add a DefaultWindow that takes the entire screen and add your widgets to that, the DefaultWIndow will steal keyboard focus once you click on it. I haven't tested it but I recall this working for me, hopefully I am not wrong.
Yeap, that's also what I was trying at first. Of course all my windows are children of a "DefaultWindow", so I set the size of my GUI sheet to 100% of the screen to capture all clicks, but as Eddie already said, that isn't working yet.
CrazyEddie wrote:So you might for example use the GlobalEventSet with the event "Window/MouseButtonDown", and test if the target window is an editbox, if not find the active editbox and deactivate.
I gonna feedback whether it works soon. Thanks for the fast replies.
Cryst
Re: remove keyboard input focus
Posted: Mon Jun 06, 2011 12:04
by Cryst
Works fine. Here my code for the following generations.
Registering the global event
Code: Select all
CEGUI::GlobalEventSet::getSingleton().subscribeEvent(CEGUI::Window::EventNamespace + "/" + CEGUI::Window::EventMouseButtonDown,
CEGUI::Event::Subscriber(&Application::mouseButtonDown, this));
Handling the event (in this case focus is only lost when the user left clicks):
Code: Select all
// "test3d/ChatInput" is my EditBox
bool Application::mouseButtonDown(const CEGUI::EventArgs &e)
{
const CEGUI::MouseEventArgs& mouseeventargs = static_cast<const CEGUI::MouseEventArgs&>(e);
if (mouseeventargs.button == CEGUI::LeftButton &&
mouseeventargs.window != CEGUI::WindowManager::getSingleton().getWindow("test3d/ChatInput"))
CEGUI::WindowManager::getSingleton().getWindow("test3d/ChatInput")->deactivate();
return true;
}
Thanks again,
Cryst