# JUCE\_MAC event problems

**URL:** <https://forum.juce.com/t/juce-mac-event-problems/5615>\
**Category:** General JUCE discussion\
**Created:** [August 30, 2010, 3:48pm UTC](https://forum.juce.com/t/juce-mac-event-problems/5615 "2010-08-30T15:48:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![scrgiorgio](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@scrgiorgio](https://forum.juce.com/u/scrgiorgio)\
**Post date:** [August 30, 2010, 3:48pm UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/1 "2010-08-30T15:48:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 30, 2010, 4:17pm UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/2 "2010-08-30T16:17:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![scrgiorgio](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@scrgiorgio](https://forum.juce.com/u/scrgiorgio)\
**Post date:** [August 30, 2010, 4:20pm UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/3 "2010-08-30T16:20:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 30, 2010, 4:50pm UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/4 "2010-08-30T16:50:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![scrgiorgio](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@scrgiorgio](https://forum.juce.com/u/scrgiorgio)\
**Post date:** [August 30, 2010, 5:36pm UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/5 "2010-08-30T17:36:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![scrgiorgio](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@scrgiorgio](https://forum.juce.com/u/scrgiorgio)\
**Post date:** [August 31, 2010, 9:35am UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/6 "2010-08-31T09:35:56Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 31, 2010, 10:30am UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/7 "2010-08-31T10:30:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![scrgiorgio](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@scrgiorgio](https://forum.juce.com/u/scrgiorgio)\
**Post date:** [August 31, 2010, 12:34pm UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/8 "2010-08-31T12:34:00Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 31, 2010, 12:43pm UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/9 "2010-08-31T12:43:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![scrgiorgio](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@scrgiorgio](https://forum.juce.com/u/scrgiorgio)\
**Post date:** [September 1, 2010, 8:24am UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/10 "2010-09-01T08:24:31Z")

</div>

Reinstalled Xcode in MacOsx.  
Not it works!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 1, 2010, 9:32am UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/11 "2010-09-01T09:32:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![scrgiorgio](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@scrgiorgio](https://forum.juce.com/u/scrgiorgio)\
**Post date:** [September 1, 2010, 10:23am UTC](https://forum.juce.com/t/juce-mac-event-problems/5615/12 "2010-09-01T10:23:23Z")

</div>

Probably. I also uninstalled macports.
