Correct way to compare for keypress?

Should this work to compare for an alphabet keypress? It does work on Windows and Mac Os. But on Ubuntu 16.04 it does not work. Some other (non alphabet) keypresses do appear to work.

bool MainContentComponent::keyPressed(const juce::KeyPress &ev)
  if (ev == 'F') { /*do my stuff*/ }

No, it’s a bit misleading because the compiler is implicitly casting the char to an int, but the operator== is actually expecting a keycode, not ascii.

Try ev.getTextCharacter() == β€˜f’ maybe?

1 Like