How does they keyboard input work in onKey()?

	void onSelectKey(const SelectKeyEvent& e) override {
		if (e.key == GLFW_KEY_BACKSPACE) {
			// Rub the last character...
			if (module->patternName[module->CurrentPattern].length() > 0)
				module->patternName[module->CurrentPattern] = module->patternName[module->CurrentPattern].substr(0, module->patternName[module->CurrentPattern].length() - 1);
			e.consume(this);
			return;
		}
		TransparentWidget::onSelectKey(e);
	}

Thanks, but this delete the module And other keys (A, B, C) are ignored!

I’m tired for this evening, I prefer to stop today, coming back tomorrow.

Thanks for helps Michael & Dave French, but doesn’t work ATM.

Perhaps tomorrow (France time) will be a better day! :wink:

Probably need to see your entire module code to offer more advice. Is the widget you’re adding these handlers to actually receiving the event? What is the box size of the widget and where is your mouse when you hit backspace? Is another widget processing the event first?

Here’s a working example of consuming key events in a custom widget: monome-rack/TeletypeScreenWidget.cpp at main · Dewb/monome-rack · GitHub

This code seems interesting, testing it tomorrow (here: GMT + 1, France) :wink:

Thanks!

Finally I keep the onHoverKey() system, despite the BACKSPACE deletes the module (I don’t understand why e.consume(this) (followed or not by return; is unefficient - perhaps the module deletion is priority, I don’t know. Also I don’t understand why two keys are reserved for… module deletion (Backspace, Delete) :roll_eyes: (IMHO, Delete key only was sufficient, why backspace?). By this way, I’ll must use left Ctrl (left Command on Mac) to rub the lastest entered char(s)!

Other text input modes/methods aren’t efficient for my usage, because:

  • Multi-line (via Enter / keypadEnter keys). I don’t want multi-line.
  • UTF-8, I don’t want it, because I limit to some ASCII characters (letters & caps non accent, digits, some symbols, nothing else).

Thanks again to persons here for your help & suggestions, yesterday. :wink:

1 Like