Disable Default Hotkey Function

General discussion about Custom Buttons, including feature requests.

Disable Default Hotkey Function

Postby steve.marks59 » Fri Apr 21, 2017 8:07 pm

How (code?) does Custom Buttons disable the default hotkey function when a hotkey is chosen in the Button Settings Tab?
steve.marks59
 
Posts: 427
Joined: Fri Dec 23, 2011 11:23 pm
Location: Claymont, Delaware

Re: Disable Default Hotkey Function

Postby morat » Sun Apr 23, 2017 1:06 am

You can use a keypress event listener to change a keyboard shortcut.

e.g.

Forward History: Alt+Right Arrow
Backward History: Alt+Left Arrow

Code: Select all
/*Code*/
var uid = "__unique_identifier_" + this.id;
if (uid in window) {
  window.removeEventListener("keypress", window[uid], true);
  delete window[uid];
} else {
  window[uid] = function (event) {
    if (event.altKey && event.keyCode == event.DOM_VK_LEFT) {
      event.preventDefault();
      event.stopPropagation();
      alert("Back");
    }
    if (event.altKey && event.keyCode == event.DOM_VK_RIGHT) {
      event.preventDefault();
      event.stopPropagation();
      alert("Forward");
    }
  };
  window.addEventListener("keypress", window[uid], true);
}
this.onDestroy = function (reason) {
  if (uid in window && reason == "update") {
    window.removeEventListener("keypress", window[uid], true);
    delete window[uid];
  }
  if (uid in window && reason == "delete") {
    window.removeEventListener("keypress", window[uid], true);
    delete window[uid];
  }
};
morat
 
Posts: 920
Joined: Wed Dec 28, 2011 2:38 pm

Re: Disable Default Hotkey Function

Postby steve.marks59 » Mon Apr 24, 2017 3:38 pm

THANKS Morat for the code.
Where in this code are the history
forward and backwards codes?
steve.marks59
 
Posts: 427
Joined: Fri Dec 23, 2011 11:23 pm
Location: Claymont, Delaware

Re: Disable Default Hotkey Function

Postby morat » Mon Apr 24, 2017 11:57 pm

The back & forward commands are in the browser.xul file.

Code: Select all
BrowserBack();

Code: Select all
BrowserForward();

view-source:chrome://browser/content/browser.xul
morat
 
Posts: 920
Joined: Wed Dec 28, 2011 2:38 pm

Re: Disable Default Hotkey Function

Postby steve.marks59 » Tue Apr 25, 2017 7:44 pm

I am sorry morat I did not state my question more clearly.
What I wanted to know is what part in this code you posted:

Code: Select all
    var uid = "__unique_identifier_" + this.id;
    if (uid in window) {
      window.removeEventListener("keypress", window[uid], true);
      delete window[uid];
    } else {
      window[uid] = function (event) {
        if (event.altKey && event.keyCode == event.DOM_VK_LEFT) {
          event.preventDefault();
          event.stopPropagation();
          alert("Back");
        }
        if (event.altKey && event.keyCode == event.DOM_VK_RIGHT) {
          event.preventDefault();
          event.stopPropagation();
          alert("Forward");
        }
      };
      window.addEventListener("keypress", window[uid], true);
    }
    this.onDestroy = function (reason) {
      if (uid in window && reason == "update") {
        window.removeEventListener("keypress", window[uid], true);
        delete window[uid];
      }
      if (uid in window && reason == "delete") {
        window.removeEventListener("keypress", window[uid], true);
        delete window[uid];
      }
    };


Assigns the Forward and Back functions to the ALT RIGHT and ALT LEFT key presses?
steve.marks59
 
Posts: 427
Joined: Fri Dec 23, 2011 11:23 pm
Location: Claymont, Delaware

Re: Disable Default Hotkey Function

Postby morat » Tue Apr 25, 2017 11:08 pm

The following shortcuts are default keys.

Back a page: Alt + Left Arrow
Forward a page: Alt + Right Arrow

The code changes the default BrowserBack() command to alert("Back") and the default BrowserForward() command to alert("Forward").

You can disable the default keys by removing the alert boxes from the code.
morat
 
Posts: 920
Joined: Wed Dec 28, 2011 2:38 pm

Re: Disable Default Hotkey Function

Postby steve.marks59 » Fri Apr 28, 2017 6:59 am

THANKS Morat for your patience.
I understand now, thanks for taking
the time to explain this to me.
I appreciate it.
steve.marks59
 
Posts: 427
Joined: Fri Dec 23, 2011 11:23 pm
Location: Claymont, Delaware


Return to General Discussion

cron