Related issues, PRs or discussions
#20750
What is the current state of the codebase?
It is currently not possible to distinguish between keyboard input generated by the user pressing a key, and that generated by system key repeat when they continue to hold a key down.
Why are changes required?
For some scripts, it may be desirable to only perform an action when the gesture that triggered the script is first performed, even if the key combination is held down.
What technical changes are required?
Both options:
- Add an
isAutoRepeat: bool = False attribute to inputCore.InputGesture.
- Modify
keyboardHandler.internal_keyDownEvent to keep track of the most recent non-modifier key. When building the InputGesture, if the current set of modifier and non-modifier keys is equal to the previous set of modifier and non-modifier keys, set isAutoRepeat = True.
- Ensure that
keyboardHandler.internal_keyUpEvent unsets the non-modifier key when released.
Then, either:
- Scripts that wish to perform an action only on the initial press of a key can return early if
gesture.isAutoRepeat == True; or
- Alternatively:
- Add the ability for scripts to specify whether they should be executed for system key repetitions. For instance, with a
allowOnRepeat: bool = True parameter to scriptHandler.script.
- Update
inputCore.InputManager.executeGesture to skip gestures where gesture.isAutoRepeat and not gesture.script.allowOnRepeat.
- The
isAutoRepeat attribute could be made internal if this approach is taken.
Are the proposed technical changes API breaking?
No:
- The modifications to
inputCore.InputGesture are additive;
- The modifications to
keyboardHandler.internal_keyDownEvent and internal_keyUpEvent only affect the types of state it tracks, which will be held in new module-scoped variables.
- If scripts have to manage this themselves, the change is opt-in only; the default behaviour remains the same.
- If a new parameter is added to
scriptHandler.script, its default maintains the current behaviour; scripts must opt in to the new behaviour explicitly.
Are there potential risks or issues with the proposed implementation?
Involves a new module-level variable in keyboardHandler.
The new logic should be reviewed carefully; mistakes in the keyboard proc have the potential to render the keyboard unusable.
Related issues, PRs or discussions
#20750
What is the current state of the codebase?
It is currently not possible to distinguish between keyboard input generated by the user pressing a key, and that generated by system key repeat when they continue to hold a key down.
Why are changes required?
For some scripts, it may be desirable to only perform an action when the gesture that triggered the script is first performed, even if the key combination is held down.
What technical changes are required?
Both options:
isAutoRepeat: bool = Falseattribute toinputCore.InputGesture.keyboardHandler.internal_keyDownEventto keep track of the most recent non-modifier key. When building theInputGesture, if the current set of modifier and non-modifier keys is equal to the previous set of modifier and non-modifier keys, setisAutoRepeat = True.keyboardHandler.internal_keyUpEventunsets the non-modifier key when released.Then, either:
gesture.isAutoRepeat == True; orallowOnRepeat: bool = Trueparameter toscriptHandler.script.inputCore.InputManager.executeGestureto skip gestures wheregesture.isAutoRepeat and not gesture.script.allowOnRepeat.isAutoRepeatattribute could be made internal if this approach is taken.Are the proposed technical changes API breaking?
No:
inputCore.InputGestureare additive;keyboardHandler.internal_keyDownEventandinternal_keyUpEventonly affect the types of state it tracks, which will be held in new module-scoped variables.scriptHandler.script, its default maintains the current behaviour; scripts must opt in to the new behaviour explicitly.Are there potential risks or issues with the proposed implementation?
Involves a new module-level variable in
keyboardHandler.The new logic should be reviewed carefully; mistakes in the keyboard proc have the potential to render the keyboard unusable.