dmauro / Keypress

A keyboard input capturing utility in which any key can be a modifier key.
http://dmauro.github.io/Keypress/
Apache License 2.0
3.18k stars 313 forks source link

`ctrl num -` and `ctrl num =` - cannot get combos to work #116

Closed iongion closed 8 years ago

iongion commented 8 years ago

For the combos bellow:

    // shuttle xpress - small wheel
    this.listener.register_combo({
      keys: 'ctrl num -',
      prevent_default: true,
      on_keydown: () => {
        console.debug('decrease val');
      },
    });
    this.listener.register_combo({
      keys: 'ctrl num =',
      prevent_default: true,
      on_keydown: () => {
        console.debug('decrease val');
      },
    });

Although the behavior is correct and it actual hooks on the right keys, the events callbacks are not invoked, none of the on_keydown, on_keyup, on_release

What can be done to overcome this ?

iongion commented 8 years ago

I have a strange device - ShuttleXpress that by default sends some weird key combinations that must be hijacked to prevent default behavior(zooming the browser content).

For small wheel rotation to the right I see the following sequence of events:

// appear altogether when motion starts
{keyCode: 144, location: 0, ctrlKey: false, altKey: false, shiftKey: false…}
{keyCode: 17, location: 1, ctrlKey: true, altKey: false, shiftKey: false…}
{keyCode: 187, location: 0, ctrlKey: true, altKey: false, shiftKey: false…}
// small pause, it appears after the first 3 logs above and when motion stops
{keyCode: 144, location: 0, ctrlKey: false, altKey: false, shiftKey: false…}

I looked inside the source code of keypress to see what these codes map to:

Now I do not really understand how to read it, it could be: num + [ctrl + = ]

Add this to my code:

    this.listener.register_combo({
      keys: 'num ctrl =',
      prevent_default: true,
      on_keydown: () => {
        console.debug('decrease val');
      },
    });

I see the default behavior is prevented(no more zoom ocurring) but as mentioned before, on_keydown does not get invoked.

iongion commented 8 years ago

Investigated even more and apparently this is the key combo:

start rotation
144 - down
144 - up 
17 - down 
187 - down 
187 - up 
17 - up 

stop rotation
144 - down
144 - up

How can this be mapped to Keypress.js ?

dmauro commented 8 years ago

If your browser is sending keypress events, I don't think that we can guarantee that they will happen in any sort of sane manner. On keydown not getting called is probably a result of the weird behavior. Try on keyup or on keypress, but probably it's just not compatible.