How does they keyboard input work in onKey()?

The docs say it’s physical keys, rather than reflecting they layout. so if I press key key next to the tab key that English speakers know as the “A” key, I expect to get GLFW_KEY_A. But If I press that key on a French keyboard, will I get GLFW_KEY_A or GLFW_KEY_Q?

Pressing the top-left key should make e.key give GLFW_KEY_A on French/AZERTY keyboards. It is based on what your operating system thinks the label on the key is. In Rack v1, e.scancode is also available, which would give GLFW_KEY_Q regardless of the keyboard, based on the position of the key on a QWERTY keyboard.

Oh, great, thanks! Just to be sure I get it, that means if I want a keyboard shortcut to be “ctrl-a”, and I used e.key it will be they key that is labeled “A”, regardless of keyboard layout? That’s what I want.

Hello - I presume onKey() doesn’t exist anymore in Rack v2 API?

https://vcvrack.com/docs-v2/structrack_1_1widget_1_1Widget_1_1KeyBaseEvent#details

Thanks, but I’ve seen it, I can’t understand how it works, how to implement. No usage example, nowhere… Ton of code examples about mouse, nothing about keyboard handling!

Have another post here: Handling non-text key on non-US keyboards? - #8 by Ohmer

Thank you, anyway.

VCV Rack API: rack::widget::Widget Struct Reference has the methods to override depending on Key (physical device location HID code (int key) or GUI (int scancode)) or Text (String unicode).

Thanks Simon, but I’m staying in the fog… Private message is possible?

I’ve tried onHoverKey (over a transparent widget, in order to give a free name, to a std::string variable, displayed in this widget - it’s a touchscreen-like), this works (QWERTY US) but… unfortunately I cannot rub last entered char by using BACKSPACE key, because this keypress… also deletes the module!

The API v2, as is, isn’t understandable. No implementation (simple) example…

Thanks in advance.

Dominique - Ohmer Modules / OhmerPrems plugins.

To avoid this, you need to consume the event, then refrain from chaining to the base method. Something like this:

void onHoverKey(const HoverKeyEvent& e) override
{
    if (e.key == GLFW_KEY_BACKSPACE)
    {
        processBackspaceKey();   // your backspace action here
        e.consume(this);
        return;
    }
    ModuleWidget::onHoverKey(e);
}

Thanks Don, exactly was I done, by using either e.consume(this), and return; just behind, but the module is removed from the rack!

However, I’ll retry by using your code - thanks again - (will be complete after test)

OK, if that doesn’t work, try looking at the source code for the VCV Notes module. You can press backspace while editing, and it deletes the previous character you typed, instead of deleting the module.

Can’t compile! error.

What class are you adding the method onHoverKey to?

Okay, now compile, no error…

… but the Backspace key delete the module!

Is processBackspaceKey() defined an API function/method? or any function/methode name?

OK, I think it’s time to study the source code for the VCV Notes module. Just do whatever it does to process the backspace key.

1 Like

Ok it’s an idea! Thanks Don, I’ll checking VCV Notes source code, perhaps it helps.

It looks like VCV Notes uses a class called TextField that processes keys here. I don’t know what you are trying to do, but if it’s to allow people to enter text, perhaps you should use this existing class.

1 Like

VCV Notes seems to use setText() and getText()

image

The feature is - at the moment - frozen, I’m tied because I’m fighting since yesterday to enter a simple line text. But it’s a pain! I’ve tried a context menu, doesn’t work… Now going away development for evening and night, be sure I’ll need to ventilate my 59-yrs old brain :rofl:

Many thanks, Don! :wink:

1 Like

the getText() setText() are just used to access the displayed widget text.

If what you are looking for is a text widget, where you can access the text as a std::sring, I would agree with @cosinekitty about using VCV notes as a reference. I done just this the other day when I wanted four for a module.

What I done was to inherit from LedDisplayTextField, in the constructor to define fonts and colours. In step() you have to handle the setting of the displaytext data, if it is changed progmatticly, I have followed Andrew’s example, and simply used bools to indicate when the field needs updating. onChange should be overridden to save the data entered into the widget to the std::string. I have placed this std::string in my module class.

You will also need to create a class inherited from LedDisplay and this is where you set the size of the widget.

finally, in the module widget constructor, you add the widgets as children.

I hope this is some help, and I have not just taught you how to suck eggs.

I think you almost have it, but you need to also override onSelectKey() and not just onHoverKey() to completely prevent the default behaviors.

Your widget doesn’t have to inherit from TextDisplay (though you certainly could use it if its behaviors meet your needs.)