ScriptCommandData.func.qualifiers always "none" when combined with @keydown

I just ran into an issue where I don't get qualifier keys reported in ScriptCommandData.func.qualifiers when the button script calls the user command from a @keydown modifier conditional.
In fact, when there is any @keydown modifier present in the button script

Command MYCOMMAND:

function OnInit(initData){
	initData.name = "Test Command";
	initData.version = "0.1.0";

	var cmd = initData.AddCommand();
	cmd.name = "MYCOMMAND";
	cmd.method = "OnCmd";
	cmd.label = "MYCOMMAND";
	cmd.template = "STR";
}

function OnCmd(data){
	DOpus.Output(data.func.args.STR + " <--> " + data.func.qualifiers);
}

Button script:

@keydown:ctrl
MYCOMMAND ctrl
@keydown:none
MYCOMMAND none
@keydown:shift
MYCOMMAND shift
@keydown:any
MYCOMMAND any

Always gives "none":

2024-08-15 16:39 Test Command: none <--> none
2024-08-15 16:39 Test Command: ctrl <--> none
2024-08-15 16:39 Test Command: any <--> none
2024-08-15 16:39 Test Command: shift <--> none
2024-08-15 16:39 Test Command: any <--> none
2024-08-15 16:39 Test Command: any <--> none

Only when there is no @keydown modifier in the script will the script get the qualifiers:

MYCOMMAND NoModifier

Gives

2024-08-15 16:45 Test Command: NoModifier <--> none
2024-08-15 16:45 Test Command: NoModifier <--> ctrl
2024-08-15 16:45 Test Command: NoModifier <--> shift
2024-08-15 16:45 Test Command: NoModifier <--> alt
2024-08-15 16:45 Test Command: NoModifier <--> shift,ctrl
2024-08-15 16:45 Test Command: NoModifier <--> shift,alt
2024-08-15 16:45 Test Command: NoModifier <--> ctrl,alt
2024-08-15 16:45 Test Command: NoModifier <--> shift,ctrl,alt

Note that even keydowns below will break it:

MYCOMMAND NoModifierButStillBroken
@keydown:ctrl
MYCOMMAND ctrl

2024-08-15 16:50 Test Command: NoModifierButStillBroken <--> none
2024-08-15 16:50 Test Command: ctrl <--> none

:frowning:
What's up with that?

is this still a thing/related? User command and @keydown : bug? - #4 by Leo

That is by design, to allow you to assign commands to hotkeys without the hotkey choice affecting what the command does when the command itself looks at which keys are down.

Passing arguments to the command to tell it what you want it to for each call would make the most sense here. (Or not using @keydown at all and having all the key logic in the command. Basically, it should only be in one place or the other, not two places both interpreting which keys are down and hoping things are consistent between them.)

Scripts can also use DOpus.GetQualifiers to get the "real" key state, but remember that it may not match the key state at the time the button was clicked, if the key is released between the click and when the method is called.

Grrr, that's unfortunate.
As you may have guessed, the above command was just an example to illustrate the issue :stuck_out_tongue:
Actual commands in question are already defined and I don't want to rewrite the templates, lest I run into trouble with some calling script that I forgot to adapt or something; also it doesn't fit the concept :confused:
I guess I'll use GetQualifiers first thing when the command executes.

It would be nice to have the ability to choose to pass the qualifiers through. Maybe give the gremlins among us who would prefer to live dangerously in their own chaos of "hoping things are consistent" an advanced setting to toggle that behavior on or off?
Or a new modifier like @keepqualifiers to prepend to a button command?

We'll add Func.qualifiers_raw in 13.9.6 which will return the true as opposed to filtered qualifiers.

3 Likes

Wow, thank you!! :partying_face: :heart: