Coder Social home page Coder Social logo

Comments (16)

Prinzhorn avatar Prinzhorn commented on August 30, 2024 1

If you use document.addEventListener("keyup", e => console.log(e.which, e.keyCode, e.key)) you will get keyCode 219 for ß

Oh happy day 😄

Selection_822

This is Firefox. In Chromium it's indeed 219.

from keyboardjs.

RobertWHurst avatar RobertWHurst commented on August 30, 2024

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.

jamesarosen avatar jamesarosen commented on August 30, 2024

How about at least providing a couple of hooks so that users who want to do special key handling can?

from keyboardjs.

RobertWHurst avatar RobertWHurst commented on August 30, 2024

Sure, that's easy enough. I'll likely add hooks the next release.

See issue #7

from keyboardjs.

jamesarosen avatar jamesarosen commented on August 30, 2024

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.

RobertWHurst avatar RobertWHurst commented on August 30, 2024

Yea I saw you grabbed my Hooks branch. Is that kind of what your looking for?

from keyboardjs.

RobertWHurst avatar RobertWHurst commented on August 30, 2024

Are you still looking for this @jamesarosen ?

from keyboardjs.

jamesarosen avatar jamesarosen commented on August 30, 2024

I'm definitely interested, but I haven't had a chance to investigate it myself.

from keyboardjs.

RobertWHurst avatar RobertWHurst commented on August 30, 2024

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.

jamesarosen avatar jamesarosen commented on August 30, 2024

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.

RobertWHurst avatar RobertWHurst commented on August 30, 2024

Ah... Ok I'm on it.

from keyboardjs.

RobertWHurst avatar RobertWHurst commented on August 30, 2024

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.

Prinzhorn avatar Prinzhorn commented on August 30, 2024

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.

daniel-wer avatar daniel-wer commented on August 30, 2024

@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.

Prinzhorn avatar Prinzhorn commented on August 30, 2024

@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.

Selection_820

from keyboardjs.

daniel-wer avatar daniel-wer commented on August 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.