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

Enum support, new api for keys #6

Open
Shiyan7 opened this issue Oct 6, 2023 · 2 comments
Open

Enum support, new api for keys #6

Shiyan7 opened this issue Oct 6, 2023 · 2 comments

Comments

@Shiyan7
Copy link

Shiyan7 commented Oct 6, 2023

Is it possible to add enum support for all keys? I would also like an API so that several keys could be sent to the hotkey function like this

Old version:

hotkey({
  key: 'Backspace',
  type: 'keydown',
  filter: timerModel.isRunning,
  target: clearClicked,
});

hotkey({
  key: 'Delete',
  type: 'keydown',
  filter: timerModel.isRunning,
  target: clearClicked,
});

New version:

const HOTKEYS = {
  KEYDOWN: {
    BACKSPACE: 'keydown/backspace',
    DELETE: 'keydown/delete',
  },
  KEYUP: {
    ESCAPE: 'keyup/escape',
    ENTER: 'keyup/enter',
  },
};

hotkey({
  key: [HOTKEYS.KEYDOWN.BACKSPACE, HOTKEYS.KEYDOWN.DELETE],
  filter: timerModel.isRunning,
  target: clearClicked,
});
@Shiyan7 Shiyan7 changed the title Enum support, and new api for hotkey Enum support, new api for hotkey Oct 6, 2023
@Shiyan7 Shiyan7 changed the title Enum support, new api for hotkey Enum support, new api for keys Oct 6, 2023
@Shiyan7
Copy link
Author

Shiyan7 commented Oct 24, 2023

perhaps there are options with a better API, the main point here is that these key need to be typed

@Kelin2025
Copy link
Owner

The thing is that there're not just hot "keys", but also combos. Like Ctrl+D
So enums won't work well here, it should be something like

type Key = 'Ctrl' | 'Shift' | ...
type Hotkey = `${Key}` | `${Key}+${Key}` | `${Key}+${Key}$+{Key}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants