Sign in to follow this  

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

Recommended Posts

Posted (edited)

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
c) Inkscape

Any other source available robust implementations that you know of.

Consider the following 2 psuedocode patterns

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.


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

or something like:

    foreach(k in shortCutsManager.mouseMoveKeys.keys()) {
        var keyContext=shortCutManagers.mouseMoveKeys.get(k);
    function deleteKey_mouseMoveHandler(e) {


Edited by imagenesis

Share this post

Link to post
Share on other sites

It would be exceedingly helpful (for me at least) if you could describe what the user actually is doing in these scenarios. For instance, are you talking about modifier keys? (The usual set being Ctrl, Shift, Alt, etc.) Are you talking about key combinations? (Ctrl+A, Alt+Q) Are you talking about chords? (Ctrl+K+N to use a popular Visual Studio chord)

Or maybe a single system that handles all of these input forms?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this