How to handle set of keyboard shortcuts (Statemachine eval onEvent vs chained Event handlers)

27 views
Skip to first unread message

dlots

unread,
Aug 28, 2017, 9:52:33 AM8/28/17
to Haxe
I am an avid Blender,ZBrush,Adobe,etc user and this question is within the context of systems implemented to handle (chained) shortcuts for a viewport that generally execute 2 functionalities: events responding to a shortcut press and functionality that depends on the keydown state of shortcuts.

1. Is there any literature or documentation that discusses implementing such a shortcut handling systems?
2. My position, is of the considered patterns below, #2 is correct, however are there any distinct advantages or explicit decision to use a state-machine like handling system as described in #1?
3. Of the following software, please let me know if you have any insight on their implementations:

a) Blender
b) GIMP
c) Inkscape

Any other source available robust implementations that you know of.

Consider the following 2 psuedocode patterns

    viewport.addEvent(MOUSE_MOVE,mouseMoveHandler)

    function mouseMoveHandler(e) {
        if(shortCutsManager.getKey(DELETE_KEY)) {
            doDeleteUnderMouse();
        } else if(shortCutsManager.getKey(DRAG_KEY)) {
            dragMouseMove();
        }
    }

or something like:

    foreach(k in shortCutsManager.mouseMoveKeys.keys()) {
        var keyContext=shortCutManagers.mouseMoveKeys.get(k);
        viewport.addEvent(MOUSE_MOVE,keyContext.mouseMoveHandler);
    }
    function deleteKey_mouseMoveHandler(e) {
        viewport.removeEvent(MOUSE_MOVE,currentMouseMoveHandler);
        currentMouseMoveHandler=deleteKey_mouseMoveHandler;
        doDeleteUnderMouse();
    }

My position is that the correct and effecient implementation is to maintain the explicit handler for a recurring event, eg the second implementation (#2). However, there is likely a set of developers who advocate a state-machine like implementation of #1.
Reply all
Reply to author
Forward
0 new messages