solid-primitives icon indicating copy to clipboard operation
solid-primitives copied to clipboard

createShortcut but allow any permutation

Open onx2 opened this issue 7 months ago • 2 comments

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();
});

onx2 avatar Jul 23 '24 23:07 onx2