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

createShortcut but allow any permutation #663

Open
onx2 opened this issue Jul 23, 2024 · 2 comments
Open

createShortcut but allow any permutation #663

onx2 opened this issue Jul 23, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@onx2
Copy link
Contributor

onx2 commented Jul 23, 2024

Describe The Problem To Be Solved

This may not be a bug, and if not I think it would be a nice thing to add as another function or option.

I want to use createShortcut(["Shift", "Control", "M"], () => {}) and have it trigger the function on any permutation of key presses, so how vscode does it with their shortcuts.

Suggest A Solution

I have a rough implementation of it using useKeyDownList, so something like this but maybe with also a length check?

const keys = useKeyDownList();
const myShortcut = new Set(["SHIFT", "CONTROL", "M"]);

createEffect(() => {
  const keyList = keys();
    for (const key of keyList) {
      if (!myShortcut.has(key)) return;
    }

  someCallback();
});
@thetarnav
Copy link
Member

What is your use case for that?
I’m not entirely opposed to the idea, but it might be a specific need for your app, and like you see is not hard to figure out that functionality yourself.

@onx2
Copy link
Contributor Author

onx2 commented Jul 24, 2024

I'm creating a keyboard shortcut manager for an application and want to allow a user to define keys bound to an action. Normally when triggering keybindings in software, for example VSCode, Notion, and many others, I can press at least the Modifier Keys in any order then a Character Key to trigger an action. You can see an example of this in VSCode with Shift + CMD + P or in Notion with Shift + CMD + L. I actually expected the default behavior of createShortcut to do this as it is very commonplace, at least in the software / apps I use. I'm happy to contribute to this as well!

Edit: As you mentioned above, this isn't difficult to create using the existing functions but I will admit I was a bit confused when createShortcut didn't have this behavior. If you think that it is best to keep it out I can close this and implement a custom function in my app instead - thanks for your time!

@thetarnav thetarnav added the enhancement New feature or request label Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants