this post was submitted on 10 Jun 2024
15 points (100.0% liked)

Firefox

449 readers
4 users here now

A place to discuss the news and latest developments on the open-source browser Firefox

founded 4 years ago
MODERATORS
 

I seeked into the API in order to write a plugin for myself. In order to aid my workflow I need to listen to two keystrokes closely followed.

Apparently there are only hacks available. I want to fire-and-forget about my plugin as long as the API to command firefox stays consistent.

I did not attempt to write any code (and any JS code, honestly that is) yet. Simply because I did not get that requirement addressed by the official API /& documentation.

Recompiling firefox would be the least favorable option; But I would still be hooked if it would enable me to observe keystrokes on my own.

As an practical example: Pressing Shift two times in sequence and within 100 ms should enable me to eat the event.

top 5 comments
sorted by: hot top controversial new old
[–] pe1uca@lemmy.pe1uca.dev 2 points 5 months ago

Probably you can inject your js and add an input event in the body of the page.

[–] treasure@lemmy.blahaj.zone 2 points 5 months ago

To detect two keystrokes closely followed, you can use EventListeners for the onkeyup/onkeydown event. In combination with a variable that determines if the key was already pressed within the last 100 ms and a setTimeout call that resets that variable after 100 ms, it should be fairly easy to accomplish.

[–] kevincox@lemmy.ml 2 points 5 months ago (1 children)

If you just need to intercept the keypresses in webpages then you can inject a content script and handle these. However there is no way with the new WebExtensions API to intercept browser chrome events.

Additionally there is no way to delay events. So if you want to suppress both shift presses you will struggle to do that. If you are ok to let the first one go through suppressing the second one is trivial.

[–] scmer@feddit.de 1 points 5 months ago

Thanks, @kevincox@lemmy.ml. That sums up my options.

[–] ReversalHatchery 1 points 5 months ago

Look up userscripts. They are a not officially supported feature with bad documentation. It allows you to write javascript code that affects internal state of the browser.

There are 3rd party pages with useful pieces of information. Userchrome styling (and in turn also things called firefoxcss) and the old XUL addon API docs may be helpful.

One question though. Do you have prior programming experience? Even hobby level.
I'd you don't, maybe this is not the best opportunity to learn it. You want to learn that with things that are documented, there are plenty of things like that.