Does setWantsKeyboardFoucs(false) actually block key-presses

I thought that setting setWantsKeyboardFoucs(false) would prevent keypresses to ever reach a component. Though it does not seem to work this way.
Before i dive in further can setWantsKeyboardFoucs(false) really be used to block key-presses to ever reach a component?
And if not how to disable key-presses without overriding the Component and returning false on keypressed?

If you don’t want key-presses, just don’t implement a keyPressed() method… (?)

(Or implement a keyPressed method that consumes the event and does nothing)

Well i have TreeView which i don’t want to consume keypresses, i always made the assumption that setting wantsKeyboardFocus to false would make the TreeView or any other component not receive keypresses. I think i just misunderstood, but the name sort of implies it. Anyway i subclassed the TreeView and just return false on keypressed. Although i hoped you just could block keypresseses with a flag, this is handy for when you have standard juce components that you want to block. Now you’ll always have to subclass them.

Well, wanting key focus is a completely different thing from wanting key presses… Focus just means that you get first shot at any incoming events, but if the focused component doesn’t understand a particular event, it gets passed back up the hierarchy to other parents which may be able to handle it.

It may also be possible to do what you need by adding a keylistener to your treeview, and using that to consume the events, but TBH I can’t remember whether in detail whether that’d work or not.

Wouldn’t something like setWantsKeyboardInput() be a handy thing? So you can simply let a component ignore keypresses.
Otherwise you always need to subclass it.

On another note, i know it isn’t possible but wouldn’t it be nice if there would be a way in c++ to only override a specific method of a member class instead of always needing to subclass it.
Something like this :wink:

	class MyComponent : public Component
	{
	public:
		MyComponent();
		~MyComponent();
	private:
		TreeView* view;
		//override keyPressed
		bool view::keyPressed(const KeyPress &key)
		{
			return false;
		}
	};	

Well, clearly not particularly handy, because nobody else has ever asked for it! It’s the kind of thing that I’d rather not burden the base Component class with, when you can achieve the same result in other ways.

Well that’s a bold statement. It doesn’t mean if someone never asked for a specific thing it’s by default a bad idea, wouldn’t you agree?
Anyway, i was just confused with the behavior of setWantsKeyboardFocus(), now it’s clear and i can get on with my work.

Yes, I do agree! And I’m not saying this is a bad idea! Just that when you’ve got such a widely-used class as Component, even very good ideas might not always be worth adding to it, unless they are features that would definitely be useful to a lot of people. That class is already too big, and I’d much rather be removing functionality from it than adding any more!

How do I cure this.

If I have a main DocumentWindow and I create another document window used as a plugin window container, how can I disable all key strokes from the second window. If I return false from the keyPress routine, the main dowcument does not receive the key strokes. Also if I setWantsKeyboardFocus false, the close button does not work and still the key strokes never reach the other document window.

What I need and others I assume is for a window setting that completely ignores key strokes. Is there a work around?

I tried returning windowHasCloseButton | ComponentPeer::windowIgnoresKeyPresses in getDesktopWindowStyleFlags but the key strokes still get to the window.