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

Prevent keyboard from playing if modifier key is pressed #23

Merged
merged 2 commits into from
Sep 23, 2015

Conversation

ahoym
Copy link
Contributor

@ahoym ahoym commented Sep 21, 2015

Fixes: #9

This PR:

  • Adds a check to the keydown callback to return out if a modifier key is pressed before an actual key.
  • Expands the key-simulator test helper to enable keyboardEvent.metaKey testing
  • Adds a simple test for this functionality.

Something I noticed though is that even though this works for something like Cmd + L, if someone did L + Cmd, it will still hold the L at keydown until pressed again.

Add a check to the keydown callback to return out if a modifier
key is pressed before an actual key. Expand the key-simulator
test helper to enable keyboardEvent.metaKey testing
@stuartmemo
Copy link
Owner

@ahoym Thanks for this! Seems to fail the build though. :person_with_pouting_face:

initKeyboardEvent doesn't play nicely in Firefox, and didn't register its
metaKey argument. initKeyEvent works as intended in Firefox, and doesn't
exist in Chrome. Checking for existence of the latter instead of the former
enables both test suites to pass.
@ahoym
Copy link
Contributor Author

ahoym commented Sep 22, 2015

@stuartmemo,

Gah, this was a classic case of cross browser struggles! KeyboardEvent.initKeyboardEvent in Firefox wasn't registering its metaKey argument (either that, or accepts a totally different set of parameters), so it wasn't doing what I intended for the test.

KeyboardEvent.initKeyEvent did though, and conveniently it seems initKeyEvent doesn't exist in Chrome. So I switched the conditional to prefer initKeyEvent as opposed to initKeyboardEvent and all seems well now!

@stuartmemo
Copy link
Owner

Amazing, thank you again! ⚡

stuartmemo added a commit that referenced this pull request Sep 23, 2015
Prevent keyboard from playing if modifier key is pressed
@stuartmemo stuartmemo merged commit b40cd22 into stuartmemo:master Sep 23, 2015
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

Successfully merging this pull request may close these issues.

2 participants