remove keyboard input focus

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
zola
Quite a regular
Quite a regular
Posts: 48
Joined: Wed Jan 12, 2005 12:06

remove keyboard input focus

Postby zola » Sun Sep 05, 2004 15:14

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

User avatar
zola
Quite a regular
Quite a regular
Posts: 48
Joined: Wed Jan 12, 2005 12:06

remove keyboard input focus

Postby zola » Sun Sep 05, 2004 15:37

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. :cry:

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

remove keyboard input focus

Postby CrazyEddie » Sun Sep 05, 2004 15:46

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.

User avatar
zola
Quite a regular
Quite a regular
Posts: 48
Joined: Wed Jan 12, 2005 12:06

remove keyboard input focus

Postby zola » Mon Sep 06, 2004 10:08

It works
thank You very much for the fast help

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

remove keyboard input focus

Postby CrazyEddie » Sat Sep 18, 2004 15:42

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.

Cryst
Just popping in
Just popping in
Posts: 3
Joined: Fri Jun 03, 2011 21:03

Re: remove keyboard input focus

Postby Cryst » Fri Jun 03, 2011 21:24

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/156624
Thanks for your help in advance,
Chris

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: remove keyboard input focus

Postby Kulik » Sun Jun 05, 2011 10:46

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. :)

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: remove keyboard input focus

Postby CrazyEddie » Mon Jun 06, 2011 07:39

Kulik wrote:I haven't tested it but I recall this working for me, hopefully I am not wrong. :)

I have bad news! :lol:

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

Cryst
Just popping in
Just popping in
Posts: 3
Joined: Fri Jun 03, 2011 21:03

Re: remove keyboard input focus

Postby Cryst » Mon Jun 06, 2011 11:02

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

Cryst
Just popping in
Just popping in
Posts: 3
Joined: Fri Jun 03, 2011 21:03

Re: remove keyboard input focus

Postby Cryst » Mon Jun 06, 2011 12:04

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


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 6 guests