Skip to content

Handling Shift key on Android Chrome Device #40

@Greensahil

Description

@Greensahil

QR Code to reproduce issue:

image

If I go to the onScan.js playground website:
https://www.a.kabachnik.info/onscan-js-playground.html

And if I scan the QR code above using a Zebra DS2278 Scan Gun, connected to my dell laptop:

You will see that at a certain point alt key is sent (i.e. keycode 18)
image.

KeyCode "96 " is the num lock key 0. If I scan using the same barcode gun in an Android device and chrome browser, it scans the alt key code 18 as well but after that instead of returning "96" in the next line it returns "48" keycode for 0 (which is fine as both of them are equivalent to 0). However, on the android the next line item is unIdentifined on the browser.

I am assuming this is just the browser/os interpreting the ascii code sent by the gun differently or translating the same ascii codes into different keycodes. These are the results from the playground, put into a diffchecker website. The one on the left is from the computer and the right is from an android phone. Every time there is a shift key sent before keycode for 0 or actually 0 to 9 (keycode 48 to 57) it results in unidentified.

image

Now if I scroll down there are certain cases where the PC also gets keycode 48:

image

However, this time around both the PC chrome browser and the Android chrome browser is able to interpret it properly because there is no alt key before this. This is just my assumption that this might have something to do with the alt key but I am not sure. My work around that seems to be working for now has been to add this on the KeyCodeMapper(oEvent): method of this libaray:



    if(oEvent.which === 48){
      if(oEvent.shiftKey){
        return ')';
      }
      return '0';
    }

    if(oEvent.which === 49){
      return '1';
    }

    if(oEvent.which === 50){
      return '2';
    }

    if(oEvent.which === 51){
      return '3';
    }

    if(oEvent.which === 52){
      return '4';
    }

    if(oEvent.which === 53){
      return '5';
    }

    if(oEvent.which === 54){
      return '6';
    }

    if(oEvent.which === 55){
      return '7';
    }

    if(oEvent.which === 56){
      return '8';
    }

    if(oEvent.which === 57){
      if(oEvent.shiftKey){
        return '(';
      }
      return '9';
    }

Does someone have an idea about what might be causing this? The library is obviously interpreting the keycodes properly but when followed by an alt key it just returns undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions