// ==UserScript==
// @name Mouse Button Remapper
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Remap mouse side buttons to keyboard buttons
// @author You
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Map mouse button IDs to keyboard key codes
const buttonMappings = {
3: 'P', // Change this to the desired key code
4: 'O' // Change this to the desired key code
// Add more mappings as needed
};
// Add event listener for mouse button press
window.addEventListener('mousedown', function(event) {
const buttonId = event.button;
if (buttonMappings[buttonId]) {
// Simulate keydown event for the mapped key
const keyEvent = new KeyboardEvent('keydown', {'key': buttonMappings[buttonId]});
document.dispatchEvent(keyEvent);
}
});
// Add event listener for mouse button release
window.addEventListener('mouseup', function(event) {
const buttonId = event.button;
if (buttonMappings[buttonId]) {
// Simulate keyup event for the mapped key
const keyEvent = new KeyboardEvent('keyup', {'key': buttonMappings[buttonId]});
document.dispatchEvent(keyEvent);
}
});
})();
I dont know any other ways to solve this. suggest anything please. I dont know chromes code.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/cZeDvX4
Comments
Post a Comment