Toggle Keys and Gestures
-
This mod uses a command chain button as basis and adds following functionality
- Toggle keyboard shortcuts and mouse gestures, individually or together
- Highlight color to indicate when one of the two, or both, are disabled
- Shows current status of these preferences in the title and updates the status however the preferences are changed (button, settings, shortcuts, menu, etc.)
This is a javascript modification. To install the script follow instructions outlined in the official guide ☛ https://forum.vivaldi.net/post/10549
Additional steps:
- Visit
vivaldi://settings/qc
and create a new command chain by clicking on the+
button - Chain Name:
Toggle Keys and Gestures
. The default command is a delay of 1000, which does nothing and therefore fits the purpose perfectly - Open the toolbar editor (either right‐click an existing toolbar button and select »customize toolbar«, or type »customize toolbar« in quick commands)
- Inside the toolbar editor popup select »command chains« from the dropdown, find the »Toggle Keys and Gestures« button and drag it to the toolbar of your choice
- Add following code to your custom Javascript file:
// Toggle Keys and Gestures // version 2023.5.0 // https://forum.vivaldi.net/post/622831 // Button for toggling keyboard shortcuts and mouse gestures. Highlight // indicates whether something is disabled. Can be toggled together or // individually (shift‐click/alt‐click). See instructions on the forum for // creating a custom icon. (function toggleKeysAndGestures() { function run(e, el) { vivaldi.prefs.get(sk, (k) => { vivaldi.prefs.get(sm, (m) => { if (e !== null && !e.ctrlKey) { if (e.shiftKey) { if (k === true) k = false; else k = true; } else if (e.altKey) { if (m === true) m = false; else m = true; } else { if (k === true) k = false; else k = true; if (m === true) m = false; else m = true; } vivaldi.prefs.set({ path: sk, value: k }); vivaldi.prefs.set({ path: sm, value: m }); } if (k === false || m === false) { el.style = "color: var(--colorHighlightBg)"; } else { el.style = "color: unset"; } el.title = "Toggle Keys and Gestures"; if (k === true) el.title += "\n\u{2022} Keys enabled (shift)"; else el.title += "\n\u{2022} Keys disabled (shift)"; if (m === true) el.title += "\n\u{2022} Gestures enabled (alt)"; else el.title += "\n\u{2022} Gestures disabled (alt)"; }); }); } const sk = "vivaldi.keyboard.shortcuts.enable"; const sm = "vivaldi.mouse_gestures.enabled"; let check = 0 let appendChild = Element.prototype.appendChild; Element.prototype.appendChild = function () { if (this.tagName === "BUTTON") { setTimeout( function () { if ( this.title === "Toggle Keys and Gestures") { run(null, this); const toggle = (event) => run(event, this); this.addEventListener("click", toggle); if (check === 0) { vivaldi.prefs.onChanged.addListener((e) => { if (e.path === sk || e.path === sm) run(null, this); }); check = 1; } } }.bind(this, arguments[0]) ); } return appendChild.apply(this, arguments); }; })();
History
- 2022.11.0 Release
- 2023.5.0 Update for custom icons
-
Hi, thank you for making this awesome mod, can you add more feature into this mod please?
-
Add CLICK+Hold (or whatever key modifier) to always enable both Vivaldi KB & MG regardless of their state. This will allow user to reset back to normal quickly.
-
Option to limit disabled KB/MG shortcut only when focusing on website; auto enabled both when switch focus to Vivaldi's GUI (panel/tabbar/mail/statusbar). Basically limit the disabled state to only when user interact with
#webpage-stack
orwebview
, that way we don't need to constantly switching back & forth when accessing the browser GUI. -
Add function to disable/enable active tab's website shortcut into the button, basically combined your other js mod to disable website shortcut with this mod.
-
Maybe add a combo command for disabled Vivaldi KB/MG & enabled website shortcut at once?
Thanks again for your great work! -
-
- If the icon isn’t highlighted, you know the states are synced. If it is highlighted and you know the states aren’t synced, either shift‐ or alt‐click, doesn’t matter. Afterwards the states will be synced. I would introduce it, but ctrl doesn’t work. Two modifiers are a clunky workaround and long press complicates things. I don’t really see this as an issue.
- I’d have to look into this. Probably a bunch of logic needed with additional observers for tab switching and URLs and automatically changing both preferences and button state.
- /4. One is a modification (UI), the other is a userscript(webpage). Combining is hard and doesn’t seem worthwhile, because you can create a black/whitelist in the userscript header (currently it runs on all pages, simply adjust it).
-
@luetage The icon display seems to be a bit wonky, not updating when I use the keyboard shortcut to enable/disable keys. Any advice?
-
@legobuilder26 I never brought the update to the mod here. We have custom buttons now, there is no reason to load a toolbar icon with Javascript. See first post for the updated version.