numlock key registering as S key

Discussion in 'Support!' started by angrytiki, June 26, 2017.

  1. angrytiki

    angrytiki New Member

    Messages:
    1
    Likes Received:
    0
    Because I use my numlock key as my mic button this has caused a lot of my units to cancel building stuff. I had my friend try it and it registered as S for him too. I know I could just use a different key and this is a non-issue for probably everyone else but I'm used to using numlock and can't think of any reason it would register as the S key intentionally.
  2. chuck251991

    chuck251991 New Member

    Messages:
    2
    Likes Received:
    3
    Hey there angrytiki,

    My guess would be that numlock is being read in a scancode (like on the SDL page that I can't link titled "SDL Keycode Lookup Table"), then the high order bits are being dropped. Note that the scancode value of numlock is 0x40000053, so if we drop the high order bits we end up with 0x0053, which we can see in /media/ui/main/shared/js/keyboard.js is mapped to 's'.

    I don't have a fix yet, but maybe this will help the devs. Good luck!
    angrytiki likes this.
  3. chuck251991

    chuck251991 New Member

    Messages:
    2
    Likes Received:
    3
    Ok, I figured it out. Some parts of the UI utilize a Javascript library called Mousetrap. This library makes a call to String.fromCharCode, which only returns the bottoms 2 bytes of the integer it's passed. For you, I've made a mod (attached) which intercepts the numlock keypress and prevents it from propagating.

    More long-term options outside of my power:
    • Upgrade to Mousetrap 1.6.0 and add the numlock key as a key binding (haven't tested this)
    • Replace the calls to Mousetrap.characterFromEvent with a custom function that examines event.which and returns the correct string (like NumLock). I had this working pretty well, but wasn't able to get it into a mod

    Attached Files:

    angrytiki and lulamae like this.

Share This Page