Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Custom Right Clicking Scratch Extension
- Legion999
-
Scratcher
22 posts
Custom Right Clicking Scratch Extension
I have developed a script that allows you to bring right-clicking to your scratch projects, at the cost of only being able to use it on Turbowarp, SnailIDE, or Penguin IDE. To use it, simply press the Extension button and add the “Custom Extension” button. Then, you will receive a UI screen. Click on the “Text” tab and paste the Javascript code at the bottom of the Page: (Make sure to toggle the check box, “Run Extension Without Sandbox” or else the extension won't work.) Hit load after, and it will create a block that says “Is Right Mouse Button Down” a long with a new Block Type.
(function(Scratch) {
‘use strict’;
class RightClickExtension {
constructor() {
this.rightMouseDown = false;
// Listen for the contextmenu event to detect right clicks
// and prevent the default browser menu from appearing
document.addEventListener('contextmenu', (e) => {
e.preventDefault();
});
// Track mouse button states
document.addEventListener('mousedown', (e) => {
if (e.button === 2) this.rightMouseDown = true;
});
document.addEventListener('mouseup', (e) => {
if (e.button === 2) this.rightMouseDown = false;
});
}
getInfo() {
return {
id: ‘rightclickdetector’,
name: ‘Right Click’,
blocks: [
{
opcode: ‘isRightClickDown’,
blockType: Scratch.BlockType.BOOLEAN,
text: ‘right mouse down?’
}
]
};
}
isRightClickDown() {
return this.rightMouseDown;
}
}
Scratch.extensions.register(new RightClickExtension());
})(Scratch);
(function(Scratch) {
‘use strict’;
class RightClickExtension {
constructor() {
this.rightMouseDown = false;
// Listen for the contextmenu event to detect right clicks
// and prevent the default browser menu from appearing
document.addEventListener('contextmenu', (e) => {
e.preventDefault();
});
// Track mouse button states
document.addEventListener('mousedown', (e) => {
if (e.button === 2) this.rightMouseDown = true;
});
document.addEventListener('mouseup', (e) => {
if (e.button === 2) this.rightMouseDown = false;
});
}
getInfo() {
return {
id: ‘rightclickdetector’,
name: ‘Right Click’,
blocks: [
{
opcode: ‘isRightClickDown’,
blockType: Scratch.BlockType.BOOLEAN,
text: ‘right mouse down?’
}
]
};
}
isRightClickDown() {
return this.rightMouseDown;
}
}
Scratch.extensions.register(new RightClickExtension());
})(Scratch);
- davohunter
-
Scratcher
100+ posts
Custom Right Clicking Scratch Extension
Please post this in the Developing Scratch Extensions forum not in the help with scripts forum.
- Discussion Forums
- » Help with Scripts
-
» Custom Right Clicking Scratch Extension