[Zotero 7] How to capture events of mouse side buttons

95 views
Skip to first unread message

Ziyuan Ding

unread,
Sep 10, 2024, 8:03:40 AM9/10/24
to zotero-dev
Hi, 
 
I tried to capture the mouse side button events on Zotero 7.0.4 (64-bit).

In the Chrome browser, the mouse side button will be mapped to "Forward"/"Back", which has the same effect as Alt+Left_Arrow / Alt+Right_Arrow.

I added the parameters `-ZoteroDebugText -jsconsole` after the path to the  Zotero executable file, and tried to execute below in the Browser Console after starting Zotero.

``` javascript
window.addEventListener("pointerdown", function(event) {
console.log('pointerdown', event)
}, true);
```
When I press the  mouse's left button, or right button, or scroll wheel, the console logs, but pressing the mouse side button does not respond.

I am sure that `addEventListener` should work, because in Chrome browser, this can capture the events of mouse side button, but it cannot be done in Zotero. I guess Zotero intercepts non-left and non-right button keys or something, but unfortunately I don't know where to start. I hope someone who familiar with Zotero's source code could help me.

My operating system is Windows 10 22H2 19045.4842
The mouse I use is Logitech M720:
erf9nvv87kyj5ntg41gd.png

Best Regards,
Ziyuan Ding

XY Wong

unread,
Sep 10, 2024, 8:59:46 AM9/10/24
to zotero-dev
These are not standard buttons, and different devices or drivers have different reflections for them. So, whether you can capture their events completely depends on how these buttons are defined by your device/driver/you.

Ziyuan Ding

unread,
Sep 10, 2024, 9:40:36 AM9/10/24
to zotero-dev
Thanks for your information XY Wong!

I think my device and drivers are working well. I'm not seeking a generic way of mapping it, I just want to try it on my own device, a single windows laptop.
The link you posted provided a test program of mouse events, I can play it with side buttons without any problem in web browser, but same program inside Zotero will not work for all mouse buttons.  Therefore I don't think it's a problem of devices or drivers as all tests happen on the same device.

Thanks,
Ziyuan Ding

Ben Jaeger

unread,
Sep 11, 2024, 1:43:28 PM9/11/24
to zotero-dev
If it's just a project for yourself, you could use a program like X-Mouse Button Controller which can capture mouse events and turn them into something else (including keyboard shortcuts or a bunch of other actions, you can also tell it to only change these mouse events within specific programs like Zotero) which you can then listen for instead of the side mouse buttons.

It's not a perfect fix if you're making something for other people, but it would work for a personal project just fine I think

XY Wong

unread,
Sep 11, 2024, 2:27:11 PM9/11/24
to zotero-dev
As we discussed, the behaviors of the buttons are decided by your device, your driver, and your OS. It's not about if they work "well" or not - you can reflect them to "normal" keys and they will work as you expected, as Ben suggested, otherwise they are probably not recognized as a mouse click, because they may trigger os-level messages to the app, instead of being treated a normal button click inside the app.

Zotero is based on Firefox, but they're not the same. Also, website in Firefox are non-privileged while the Zotero main window is in a privileged environment, the behaviors can differ.

So if it's only your personal project and will not be used by others and you do want to capture these buttons in your code, try setting these two prefs to false:

mousebutton.4th.enabled
mousebutton.5th.enabled

Keep in mind that these settings can have unknown side affects and you should better not use them in projects that can be used by other people.

Ziyuan Ding

unread,
Sep 12, 2024, 3:45:54 AM9/12/24
to zotero-dev
Thanks Ben Jaeger and XY Wong! I will look into it 

Best,
Ziyuan Ding

Reply all
Reply to author
Forward
0 new messages