TextEditor::keyPressed() doesn't capture key press events

This issue only occurs on macOS. It is strange that it can capture few key press events, eg. ‘delete’, ‘tab’, ‘return’, ‘4 arrows’, ‘cmd + any char-key’…all others can’t, however enabled IME or not.

Tested JUCE-demo (on macOS), also the same.

JUCE 4.3.1 (git master)
macOS:10.12.3
Xcode: 8.2.1

Sorry, but can you give an example of a keypress which doesn’t work?

??

JUCE Demo may be the best one? You could try it, Jules. Run Demo, give a breakpoint to TextEditor::keyPressed(), then make some input (feel free hit some keys) on Misc’s textEditor, you’ll find out what I’m saying is really true.

But we use text editors everywhere, and that method obviously must be receiving keypresses, otherwise text editors would never work at all!

Maybe I just don’t understand the point you’re trying to make?

Yes, Jules. That’s why I’m so confused.

We can input any characters, but seems lot of them never ‘through out’ keyPressed(). it means: if I want capture some input, I can’t implement the goal.

DId you try it in Demo?

Let me say a little more. Currently, I’m using the TextEditor::keypressed() to implement this function:

just like any IDE’s auto-complete, Intelligence tips, etc… when user input some certain characters, it’ll show a popup menu, the menu items are the tips (auto-complete content). What I did this is capture every key event by keyPressed(), then do some judge… it’s a little bit complex beyond my English level…

In addition of this, I also use keyPressed() to impelment ‘punctuation auto-match’. eg. when user input ‘[’, the ‘]’ will appear immediately, if something has been selected, the matches punctuation will auto wrap it.

and other funcy functions, shortcuts, etc… I made the TextEditor very powerful you couldn’t imagine:) All these things severe dependenced on TextEditor::keyPressed().

All of these work perfectly on Windows… but, on mac, nothing and nothing, because that method never had been called except a few key, eg.‘return’, ‘delete’, ‘tab’…

OK, I see the confusion - some of the events get sent via IME, so bypass the keyPress callback. If you want to see what’s going on, try putting your breakpoint in TextEditor::insertTextAtCaret() instead, which will always get called.

It might be better to intercept the events via a TextEditor::Listener rather than by overriding methods?

Thank God you saw my confusion :slight_smile:

All of those you said I have been used. One main reason I used keyPressed() is they have other things to do… if I put the code in, the logic will make me mad perhaps… Currently, my Editor.cpp is nearly 2000 lines. it’s a sub class of TextEditor.

and it’s nothing about IME! When I unabled (switch off) IME on mac, it’ll the same result. On Windows, both IME or not are perfect.

One more confused: why the same lib and code on Windows can, but on mac can’t?

However, I’ll give it a try again in accordance with your instructions…Thanks!

Finally, I refactoried these function :slight_smile: Guess what, Jules? I overrided TextEditor::insertTextAtCaret(), cooperate MultiTimer class. let insertTextAtCaret() method do more work :slight_smile: I know you’ll criticize on this, but ,it works perfect both on mac and Windows :))

Thanks!

and, perhaps you didn’t notice, insertTextAtCaret() will be called twice when enabled IME and input a char. The first time it is an empty and will cancel the highlight text (include press ‘del’, ‘backspace’ etc.)… so I have to use MultiTimer class and do more judge in keyPressed()…

However, I did it :slight_smile: