Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After Karabiner is (re-)started, variables of type Boolean and String are not initialized unless variable of type Integer is tested/assigned a value first... #1772

Open
Bean200505 opened this issue Jan 10, 2025 · 1 comment

Comments

@Bean200505
Copy link

Technical Details:
macOS version: macOS 15.2.0 (Sequoia)
Karabiner version: 15.3.0
Mac hardware: M4 Pro Mac mini
Keyboard hardware: Mac mini Magic Keyboard (Apple Inc.), Vendor ID: (0x004c), Product ID: (0x0322)

If I've slipped off the beam somewhere (or this has already been reported) please point out where.

Immediately after (re-)starting Karabiner, variables of type boolean and string do not appear under "Karabiner-EventViewer" >> "Variables" unless a variable of type integer is tested or assigned a value first. I've provided an example of what doesn't appear to work and a second example that does.

The following fragment doesn't appear to work as the variable tested doesn't appear under "Karabiner-EventViewer" >> "Variables" after Karabiner is (re-)started, both shift keys are pressed together, and Karabiner has had a chance to evaluate it. This appears to be the case even if the fragment appears first under "manipulators"; I suspect it's because "conditions" isn't satisfied:
...
{ "conditions": [ { "type": "variable_if",
"name": "variable_one",
"value": false
}
],
"from": { "simultaneous": [ { "key_code": "left_shift" },
{ "key_code": "right_shift" }
],
"simultaneous_options": { "key_down_order": "insensitive" }
},
"to": [ { "key_code": "vk_none" } ],
"to_after_key_up": [ { "set_variable": { "name": "variable_one",
"value": true
}
},
{ "set_variable": { "name": "variable_two",
"value": true
}
}
],
"type": "basic"
},
...

Alternatively, the following fragment works as all three variables appear under "Karabiner-EventViewer" >> "Variables" after Karabiner is (re-)started, both shift-keys are pressed, and Karabiner has had a chance to evaluate it. After this is evaluated, the original example also works on successive presses of both shift-keys:
...
{ "conditions": [ { "type": "variable_if",
"name": "variable_three",
"value": 0
}
],
"from": { "simultaneous": [ { "key_code": "left_shift" },
{ "key_code": "right_shift" }
],
"simultaneous_options": { "key_down_order": "insensitive" }
},
"to": [ { "key_code": "vk_none" } ],
"to_after_key_up": [ { "set_variable": { "name": "variable_one",
"value": true
}
},
{ "set_variable": { "name": "variable_two",
"value": true
}
},
{ "set_variable": { "name": "variable_three",
"value": 1
}
}
],
"type": "basic"
},
...

As above, if I've slipped off the beam at some point please point out where.

@tekezo
Copy link
Member

tekezo commented Jan 27, 2025

Yes, after restarting Karabiner-Elements, variables won't appear in the EventViewer until set_variable is called at least once.

Undefined variables are evaluated as 0, so you can create rules based on that assumption.
https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/conditions/variable/#specification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants