ScratchAddons / manifest-schema

Schema for the addon manifest files (addon.json) hosted on the main repository.
GNU General Public License v3.0
5 stars 10 forks source link

New setting type: key #24

Open Hans5958 opened 3 years ago

Hans5958 commented 3 years ago

No addon uses it yet, but we'll support settings of type "key". I don't think there's a real way of verifying default key combinations are correct, all I got is the JS code that detects the keys and outputs a string with them. If you wanna go crazy, build a regex for it :P

const string = e.ctrlKey
        ? "Ctrl" +
          (e.shiftKey ? " + Shift" : "") +
          (e.key == "Control" || e.key == "Shift"
            ? ""
            : (e.ctrlKey ? " + " : "") +
              (e.key.toUpperCase() === e.key
                ? e.code.includes("Digit")
                  ? e.code.substring(5, e.code.length)
                  : e.key
                : e.key.toUpperCase()))
        : "";

Originally posted by @WorldLanguages in https://github.com/ScratchAddons/manifest-schema/issues/13#issuecomment-731648777

TheColaber commented 3 years ago

This regex is not to crazy enough... /(\w|[ \+])+/ if the match is equal to the whole string, it pretty much works.

Hans5958 commented 3 years ago

This regex is not to crazy enough... /(\w|[ \+])+/ if the match is equal to the whole string, it pretty much works.

Eh, I need at least one example to know whether it works.

Hans5958 commented 3 years ago

I did some testing and I finally got this.

/^Ctrl( \+ Shift)?( \+ (.|ALT))?$/

I'll try to create a PR for this later.