Detect middle mouse click

I found this custom block for detecting a right mouse click by @dardoro, but I'm not sure how to extend it to the middle mouse button.
Smap! script pic (4)

Use the same script as the right click block, but with this code instead:

if( !window.hasOwnProperty( "middleclick")){
  middleclick = false;
  onmousedown =(e)=>{ window.middleclick = ( e.button == 1)};
  onmouseup   =( )=>{ window.middleclick = false};
}
return middleclick;

Thank you!
Can you detect other mouse events similarly? (middle mouse scrolling, previous and next buttons, cpi button)

Middle mouse scrolling can be detected with [scratchblocks]when i am [scrolled v]::control hat[/scratchblocks], and the previous and next buttons can be detected by using the above code and replacing the number with 3 or 4 respectively. Don’t know about CPI button tho (also not completely sure which one you’re talking about)

Some mouses don't have the cpi button, but it's a button behind the middle/scroll button, used (I think) for increasing mouse sensetivity/speed.

For scrolling, I want to make something like:
[scratchblocks]
< mouse scrolled [ v] :: sensing >
< mouse scrolled [up v] :: sensing >
< mouse scrolled [down v] :: sensing >
[/scratchblocks]

This reporter counts the wheel clicks since last check:

if(!window.hasOwnProperty( "wheelDelta")){
  wheelDelta = 0;
  onwheel = (e) => {wheelDelta += Math.sign(e.wheelDelta)};
}
let _wheelDelta = wheelDelta;
wheelDelta = 0;
return _wheelDelta;

right click script pic (1)

I've used your "mouse wheel" as "mouse scrolled" in this:


for
untitled script pic (10)
(it should be a cap block, but...)

If you prefer asynchronous style it can be even simpler
right click script pic (5)

right click script pic (2)
right click script pic (3)

What if you want to do something when the mouse isn't scrolling?

No-way this way :wink:

Select the text that you want to display as the link. Right-click the selection and click Topic Link. The shortcut is CTRL+SHIFT+K. In the Link ID field, enter the topic ID or the A-link keyword of the topic you want to link to.

What is the purpose of this link?

Advertising?

Wrong topic.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.