Return the old Content.setKeyPressCallback functionality (that we had for a few days)
-
There were a few days earlier this year where the global Content.setKeyPressCallback behaved like the key press callbacks for components: it always fired and you wrote your logic by filtering through the obj. object.
Then a few days later it was changed to what it is today: it asks for keyPress and lets you define different callbacks for each keypress.
Could a functionality be added where we pass some string instead of a keypress string that lets it always go off on any keypress or focus change, like it did before? This would not break existing functionality.
There are a couple of issues with the current method. Repetitive logic needs to be defined separately. If any of these keys then does something else additionally, you have to manually define it all and can't just pass a single function like you can to all other keys. If you wish to iteratively add functionality, the creating and passing a broadcaster then adding functions to that broadcaster is the way to do it. Except now you need to call the method for every single character you wish to use and pass that broadcaster, effectively recreating the entire ascii table!
-
@aaronventure The problem with the old approach was that it required a script execution for every single key stroke, regardless of whether it is actually used or not. This lead to many stability issues because they had to be executed synchronously in order to tell whether the keypress was consumed or not.
The new way is now checking for keypress matches before calling into any script, then returns true if the registered keypress matches (all within C++) and kicks off the asynchronous script callback, which is much more stable.
But a catch-all string might work, but can you elaborate the use case you're after?
-
@Christoph-Hart Ah I get it.
The use case it defining navigation behavior for keys like ESC, backspace etc. based on flags (e.g. isSettings = true) without worrying about focus which is necessary to catch keypresses with the (currently bugged) component keypress callback.
In my case it's navigation but it can honestly be anything else. I'll try to implement a functionality where Right Click > Learn takes you to a separate screen where you can see all the mappings, and if you attempt to type here it'll start typing the controller number to assign to.
By manually gating functionality of key presses with flags, I don't have to worry about juggling focus and keeping track of the focus logic if/when I add new components, and no matter what changes I make, I just have to make sure a flag is set to enable desired keyboard functionality.
-
@Christoph-Hart Btw, what is it checking against? For special keys like Backspace, it works if you type in
backspace
no matter the case, but BS, which is the character code in ASCII for backspace, does not work. -
@Christoph-Hart said in Return the old Content.setKeyPressCallback functionality (that we had for a few days):
The new way is now checking for keypress matches before calling into any script, then returns true if the registered keypress matches (all within C++) and kicks off the asynchronous script callback, which is much more stable.
But a catch-all string might work, but can you elaborate the use case you're after?
Ok this broke a lot in my projects, so it says
Does this mean I have to list every character I'm going to use in the specified keypress callback?
likeconst consumedKeys = [ "a", "b", "c", etc........];
It is a callback for user search presets
Or how do I setup a "catch-all" string? (I guess this string will cover all
-
@ulrik you can do pass in cosumedKeys = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
and follow up with any special keys you want to use
consumedKeys.concat("Escape", "Backspace", "Return", "Delete");
-
@aaronventure Or just use
setConsumedKeyPresses("all")
:)Throwing a compile error when you don't call this method is an entirely educational measure, but I think it's better if people run against a compile error that requires their attention instead of silently changing the behaviour (because here the implications are very subtle and not obvious).
-
@Christoph-Hart said in Return the old Content.setKeyPressCallback functionality (that we had for a few days):
@aaronventure Or just use
setConsumedKeyPresses("all")
:)this will throw an error
and the project will not compile -
@Christoph-Hart sorry, I opened it with an old compiled Hise app,
indeed it work, thank you @aaronventure and @Christoph-Hart ! -
-
@d-healey thanks David!