JUCE_MAC event problems


#1

I’ve a multi-platform software (which is actually working well on Linux/Windows), but I’m having some problems in Darwin.

First: I don’t get keyboard events.

class MyComponent : public Component {

virtual bool keyPressed (const KeyPress& key)
{
printf(“Key pressed\n”);
return false;
}

… all other events are ok (mousemove, mouseup,mousedown, mousedoubleclick etc etc)…
}

no matter if I use setWantsKeyboardFocus.
I see that my component gets the “focusGained” event, but any keyboard goes to the terminal. As I said the code works well in Windows/Linux.

The other problem is that I get a lot of warnings when I move the mouse wheel:

** Assertion failure in -[NSEvent deviceDeltaX], /SourceCache/AppKit/AppKit-949.54/AppKit.subproj/NSEvent.m:1715

Thanks for the help.


#2

Is this the latest version of juce? Are you building an app or a plugin?


#3

It it the latest (amalgamated) version of Juce. I’m building an app.


#4

Well keypresses very definitely work on the mac… I’m a bit stuck for ideas about what you could have done to stop it working! Try to reproduce the same thing in the juce demo and you might figure out what’s different.

The assertions are nothing to worry about, it’s just an internal Apple weirdness with certain types of mouse device.


#5

I will try to send you a small self-contained code. Thanks.


#6

This is the modified “Hello world” example.

I’ve added the following method to the MainComponent:

//key pressed
virtual bool keyPressed (const KeyPress& key)
{	
	printf("Key pressed\n");
	fflush(stdout);
	return true;
}

and in the MainComponent constructor:

	setWantsKeyboardFocus(true);
	grabKeyboardFocus();

I’m not able to get the keyPressed event in MacOsx.
Thanks.
[attachment=0]problem.zip[/attachment]


#7

That component also contains a text button, which will be given the focus in preference to its parent when the window appears. Maybe you should try actually clicking on the background to give it focus and see if that helps…!?

There’s no point calling grabKeyboardFocus() in the constructor - if a component isn’t actually on-screen or visible, it can’t be allowed to take the focus. (I wonder if I should make it assert when someone tries to do that? hmm…)

BTW you can just write DBG (“Key pressed”) instead of all that messing about with printf.


#8

Still does not work.
I tried to not add the “quitButton”. And I tried also to click on the background (to force the setFocus).
My MacOsx version i 10.5.8 Build 9L31a
gcc --version: i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465)


#9

Well it works for me, and presumably for all the other mac users because nobody else has ever complained! Do keypresses work in the juce demo?


#10

Reinstalled Xcode in MacOsx.
Not it works!


#11

That’s scary. Maybe you were linking against some messed-up versions of the SDKs or something.


#12

Probably. I also uninstalled macports.