IcarusWorks / ember-key-manager

A service for (un)binding keyboard up and down events.
MIT License
42 stars 11 forks source link

Register macro for combination of modifiers #45

Closed gossi closed 3 years ago

gossi commented 6 years ago

So, if I do want to register a macro for two (or more) modifier keys, I see multiple ways of doing it but not the one way of doing it. I guess the API isn't quite clear yet and ambigous on this point ?

jordpo commented 6 years ago

@gossi The documentation should be fairly straightforward on how to register a key macro with modifier keys. If you are talking about more allowing any combination of modifier keys than that is already defined in this enhancement issue https://github.com/IcarusWorks/ember-key-manager/issues/10.

gossi commented 6 years ago

Well, actually not quite clear yet. Image you want to register a macro for alt + control you can do it these two ways:

// 1)
manager.addMacro({
    executionKey: 'control',
    modifierKeys: ['alt'],
    keyEvent: 'keydown',
    callback: () => {
        // do something
    }
});

// 2)
manager.addMacro({
    executionKey: 'alt',
    modifierKeys: ['control'],
    keyEvent: 'keydown',
    callback: () => {
        // do something
    }
});

Now think ahead, replace one of the modifiers with a non-modifier key, e.g. make a alt + k combination, now there is only one way left of registering a macro for that.

What I'm saying, the API is still ambigous.

gossi commented 6 years ago

Hmm, thinking ahead, I think it can simplified a lot and this is all it takes:

manager.addMacro({
    keys: ['alt', 'control'],
    callback: () => {
        // do something
    }
});

the event is defaulted to keydown, unless you specify any other here. They keys will exactly say on which combination the macro is triggered. Although it can be validated upon adding the macro, if there is an invalid combination the plugin can't handle (e.g. control + k + f) and throw an error on that.

My suggestion here is (+ the other options)

manager.addMacro({
    keys: ['a'], // required
    type: 'keyup', // optional, default: 'keydown'
    allowedModifiers: ['control'], // optional, default: []
    callback: () => { } // required
});
jordpo commented 6 years ago

@gossi yes if the executionKey is a modifier key, you can do it in two ways if there are modifier keys. I don't think that is a common use case though. I think the documentation is clear that an executionKey can be a modifier key or a normal key and modifier keys have to be the supported modifier keys. In the case of two modifier keys, I think it's fine that there are multiple ways to achieve the key handling.

For allowedModifiers - that is under consideration in a separate issue.

jordpo commented 3 years ago

@gossi is this still an issue or does my last comment suffice?

gossi commented 3 years ago

sorry, I haven't used this addon for ~two years now. Given that ember has changed drastically in how it would handle such stuff, I would - as of today - look for modifiers here. I gonna close this, I consider it outdated and not up-to-date any longer.