Comments (16)
If you use
document.addEventListener("keyup", e => console.log(e.which, e.keyCode, e.key))
you will get keyCode 219 forß
Oh happy day 😄
This is Firefox. In Chromium it's indeed 219.
from keyboardjs.
I've been thinking about special keys like ?
. I would have to redesign the library's key look up system to use a hidden input to sniff the character pressed. I'm not sure I will do this because it feels unclean.
from keyboardjs.
How about at least providing a couple of hooks so that users who want to do special key handling can?
from keyboardjs.
Sure, that's easy enough. I'll likely add hooks the next release.
See issue #7
from keyboardjs.
I'll take a look at the hooks issue. You'll notice that when I raise the same issue on Keymaster, it went nowhere. This is not an easy thing to solve while keeping a low API profile.
from keyboardjs.
Yea I saw you grabbed my Hooks branch. Is that kind of what your looking for?
from keyboardjs.
Are you still looking for this @jamesarosen ?
from keyboardjs.
I'm definitely interested, but I haven't had a chance to investigate it myself.
from keyboardjs.
Are you essentially looking for a way to bind a hook that lets you modify the active keys and combos arrays? Or are you looking for a way to modify the event object passed to event handlers?
from keyboardjs.
Ideally:
// This knows that `?` can't be bound with keydown and keyup,
// but must use keypress.
KeyboardJS.bind.key('?', function() { ... });
Just fine:
KeyboardJS.bind.keypress('?', function() { ... });
Also totally acceptable, though this seems like extra setup work that many people would have to do:
KeyboardJS.bind.parseEvents = function(combo, onKeyDown, onKeyUp) {
if (combo === '?') { return { keypress: onKeyDown }; }
return { keydown: onKeyDown, keyup: onKeyUp };
};
...
KeyboardJS.bind.key('?', function() { ... });
from keyboardjs.
Ah... Ok I'm on it.
from keyboardjs.
Fixed in v0.3.0. You can bind to ? off the bat with KeyboardJS.on('?', function() {});
. If you still wish to add more macro keys use KeyboardJS.macro(keyCombo, [macrokey1, macrokey2, ...]);
. Here's an example for '?'.
KeyboardJS.macro('shift + /', ['questionmark', '?']);
Note that '?' is already part of the US locale out of the box, but if it wasn't, the above would add it. Once a macro is added you can use it in you key combos like any other key name.
from keyboardjs.
I assume a lot has changed since 2012. I'm trying to get "?" working with a German keyboard layout
This does not get me anywhere, neither "ß" nor "shift + ß" work.
keyboardJS._locale.bindKeyCode(223, ['ß']);
keyboardJS._locale.bindMacro('shift + ß', ['?']);
keyboardJS.bind('ß', console.log.bind(console, 'ß'));
keyboardJS.bind('shift + ?', console.log.bind(console, 'shift + ?'));
keyboardJS.bind('?', console.log.bind(console, '?'));
Source: https://en.wikipedia.org/wiki/German_keyboard_layout
from keyboardjs.
@Prinzhorn In case you're still interested or for anyone else who stumbles upon this, the code snippet above did not work, because the keyCode
for ß
is actually 219.
Note, however, that there is a bug in the current keyboardJS version (see #164) which affects shortcuts using secondary key symbols (as ?
) which is why only the first of the three bindings works.
from keyboardjs.
@daniel-wer I'm currently not using KeyboardJS in any project, but I might be in the future. Thanks for looking into this! How did you come up with 219? See screenshot, this is me hitting the "ß" key on this very GitHub page.
from keyboardjs.
Unfortunately, keyboard events are a mess and the keyCode is different between keydown/keyup and keypress events, because they are different types of events. There is hope, though, in the form of UI events which should make all of this easier to work with.
If you use document.addEventListener("keyup", e => console.log(e.which, e.keyCode, e.key))
you will get keyCode 219 for ß
which seems to be what keyboardJS is using. In another issue I read that @RobertWHurst plans to switch to UI events, but I'm not sure whether any work in this direction has been done yet.
from keyboardjs.
Related Issues (20)
- What is the desired behavior of preventRepeat? HOT 6
- For what reason might numeric keypad not work? HOT 3
- Sequence timing HOT 1
- HOW TO CREATE WITH A JAPANESE LOCALE? HOT 1
- Can't bind on a combo that includes a delimiter HOT 3
- Press key on electron HOT 2
- Binding arrows HOT 2
- Add watch targets to the current context rather than setting it globally
- Add integration tests for testing against common oses and browsers.
- Create a new website with proper documentation and demo HOT 3
- Releasing a binding when another activates HOT 1
- unbind keys from a specific context HOT 1
- [BUG] callback gets call incorrectly with incorrect key
- bind() with preventRepeatByDefault=true omits the first firing of pressHandler HOT 3
- ES6 is a breaking change HOT 2
- Secondary key symbols not firing event HOT 1
- Error when starting the program HOT 3
- Error TypeScript type HOT 3
- Bind characters with repetition
- Question: is it possible to unbind browser default shortcut like Command + W / Control + W HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keyboardjs.