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

Create bindings using KeyboardEvent#code value #33

Closed
vladdekhanov opened this issue Dec 12, 2023 · 3 comments
Closed

Create bindings using KeyboardEvent#code value #33

vladdekhanov opened this issue Dec 12, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@vladdekhanov
Copy link

Describe the bug
Library doesn't support code or which property to make hotkey language agnostic. It compare event key by value due to works with only one keyboard layout.

To Reproduce
Imagine you have keyboard with 2 layouts: native language and english (i.e. French and English).

Steps to reproduce the behavior:

  1. Bind event
import { bindKey } from '@rwh/keystrokes'

bindKey('H', {
	onPressed: () => {
		...
	},
	onReleased: () => {
		...
	},
});
  1. Press H button in English layout. It works
  2. Change active keybord layout to French. Press physically same button. It doesn't work what is obviously is not clear for any user.

Expected behavior
Library should work with code property (physical id of the button) and not with a key (it contains value, changable thing), otherwise library would be used only for few countries where people use english as a native language.

@RobertWHurst
Copy link
Owner

RobertWHurst commented Dec 16, 2023

I was under the impression that typically keyboard shortcuts are often standardized by key name rather than physical location on the keyboard.

I checked both Mac and Windows via these support articles as an example.

Changing the locale does not change these shortcuts. This is more relevant for application shortcuts. But I can see the issue for something like a game. Is that what you are working on?

Keystrokes uses key specifically so it is locale independent, so this is actually desired. Perhaps we need some sort of key code syntax though to allow you to choose.

@RobertWHurst RobertWHurst added the enhancement New feature or request label Dec 16, 2023
@RobertWHurst RobertWHurst changed the title Doesn't work with any other language than EN Would like to be able to create bindings using KeyboardEvent#code value Dec 16, 2023
@RobertWHurst RobertWHurst changed the title Would like to be able to create bindings using KeyboardEvent#code value Create bindings using KeyboardEvent#code value Dec 16, 2023
@RobertWHurst
Copy link
Owner

RobertWHurst commented Dec 16, 2023

@vladdekhanov alright, I've added the ability to bind code names in bindings and combos. All you need to do is prefix the name with @. For example, binding the keys in the position of the QUERTY keyboard's A and X key can be done with the combo @KeyA + @KeyX. Let me know if you have any feedback.

See the 1.5.0 release to try it out.

Thanks for raising this one @vladdekhanov

@vladdekhanov
Copy link
Author

Thanks a lot and very appreciate your quick response. I've got a flu and wasn't available to response. Thank you for solution with @ symbol. It definitely works in most cases. Looking forward to try it out and wish you a merry Christmas.

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