Some custom hotkeys can be fired with other keystrokes

Support requests, bug reports, etc. go here. Dedicated servers / VDS hosting only
haloabandoned
Bear Rating Trainee
Bear Rating Trainee
Posts: 2
Joined: 21 Feb 2014, 10:48

Some custom hotkeys can be fired with other keystrokes

Postby haloabandoned » 21 Feb 2014, 11:09

In a custom plugin, I added a hotkey for the "t" key, and now F5 suddenly fires my plugin's hotkey. I see this behavior in FF/Chrome.

After a bit of digging, it seems like in tt-rss.js and prefs.js in hotkey_handler and prefs_hotkey_handler, respectively, the following is used:

Code: Select all

var keychar = String.fromCharCode(keycode);

However, while there is some degree of overlap, a keycode (i.e. position on a keyboard) is different from a charcode (i.e. Unicode). So while Unicode 116 is a lowercase "t", keycode 116 corresponds to the F5 on a standard US keyboard.

Tested this out by hitting F4 (aka "s" if you convert it into a character) and it starred an article; wild.

I don't know if anyone other than myself cares about this "feature" (2 hotkeys for the price of 1?!), and if not, perhaps I'll just do a dirty hack / range check on it ([A-Z0-9] or something) in my local branch and leave it be for now. But figured I'd mention it in case anyone else has this trouble.

haloabandoned
Bear Rating Trainee
Bear Rating Trainee
Posts: 2
Joined: 21 Feb 2014, 10:48

Re: Some custom hotkeys can be fired with other keystrokes

Postby haloabandoned » 22 Feb 2014, 09:03

Sorry... just realized this is in the wrong forum section and don't see a way for me to move it myself. Awesome first post, dude, highfive. I promise not to post while bleary-eyed in the future.

Might not be the most elegant fix, but this seems to suit my purposes:

Code: Select all

var keychar = (keycode >= 65 && keycode <= 90) || (keycode >= 48 && keycode <= 57) ? String.fromCharCode(keycode) : '';

Cheers.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: Some custom hotkeys can be fired with other keystrokes

Postby fox » 22 Feb 2014, 13:50

Keyboard handling is one of the many things with web development that are really bad. From my experience browsers are broken in different ways with this (firefox behaved differently on os x and windows), so this might or might not work universally.


Return to “Support”

Who is online

Users browsing this forum: No registered users and 2 guests