firegestures to control keyboard shortcuts
-
- Posts: 1
- Joined: February 11th, 2009, 4:09 pm
firegestures to control keyboard shortcuts
also,
new to extension and script programming, but have had programming experience in general.
does anyone know how to use firegestures to control keyboard inputs? for example cmd + alt + y ?
from firegestures site, the key event script doesn't make much sense to me.. nothing but false next to diff mod keys?
would really appreciate any leads, as i think this should be relatively simple.
thanks!
var evt = document.createEvent("KeyEvents");
evt.initKeyEvent(
"keypress",
true,
true,
null,
false, // holds Ctrl key
false, // holds Alt key
false, // holds Shift key
false, // holds Meta key
evt.DOM_VK_F5, // presses a special key, @see http://mxr.mozilla.org/mozilla/source/d ... yEvent.idl
0 // presses a normal key, e.g. "A".charCodeAt(0),
);
document.documentElement.dispatchEvent(evt);
new to extension and script programming, but have had programming experience in general.
does anyone know how to use firegestures to control keyboard inputs? for example cmd + alt + y ?
from firegestures site, the key event script doesn't make much sense to me.. nothing but false next to diff mod keys?
would really appreciate any leads, as i think this should be relatively simple.
thanks!
var evt = document.createEvent("KeyEvents");
evt.initKeyEvent(
"keypress",
true,
true,
null,
false, // holds Ctrl key
false, // holds Alt key
false, // holds Shift key
false, // holds Meta key
evt.DOM_VK_F5, // presses a special key, @see http://mxr.mozilla.org/mozilla/source/d ... yEvent.idl
0 // presses a normal key, e.g. "A".charCodeAt(0),
);
document.documentElement.dispatchEvent(evt);
-
- Posts: 30
- Joined: July 26th, 2005, 5:46 am
Re: firegestures to control keyboard shortcuts
yes not straightforward at all unless you know the lingo
see list codes here ...
http://mxr.mozilla.org/mozilla/source/dom/public/idl/events/nsIDOMKeyEvent.idl
as I understand it ...
send an "A"
"keypress", true, true, null, false, false, false, false, 0, "A".charCodeAt(0)
send "F5"
"keypress", true, true, null, false, false, false, false, evt.DOM_VK_F5, 0
send "^a"
"keypress", true, true, null, true, false, false, false, evt.DOM_VK_CONTROL, "A".charCodeAt(0)
i can't get it to work either
see list codes here ...
http://mxr.mozilla.org/mozilla/source/dom/public/idl/events/nsIDOMKeyEvent.idl
as I understand it ...
send an "A"
"keypress", true, true, null, false, false, false, false, 0, "A".charCodeAt(0)
send "F5"
"keypress", true, true, null, false, false, false, false, evt.DOM_VK_F5, 0
send "^a"
"keypress", true, true, null, true, false, false, false, evt.DOM_VK_CONTROL, "A".charCodeAt(0)
i can't get it to work either
-
- Posts: 2
- Joined: March 16th, 2011, 4:16 pm
Re: firegestures to control keyboard shortcuts
It's quite easy.. I decided to sign up to this forum just to share this for future requests (it came up high when I looked for it on Google):
ctrl + alt + y would translate to
I created this code to switch to the next tab group (in Firefox 4)
Good luck all!
ctrl + alt + y would translate to
Code: Select all
var evt = document.createEvent("KeyEvents");
evt.initKeyEvent(
"keypress",
true,
true,
null,
true, // holds Ctrl key
true, // holds Alt key
false, // holds Shift key
false, // holds Meta key
false, // presses a special key, @see http://mxr.mozilla.org/mozilla/source/dom/public/idl/events/nsIDOMKeyEvent.idl
"y".charCodeAt(0) // presses a normal key, e.g. "A".charCodeAt(0),
);
document.documentElement.dispatchEvent(evt);
I created this code to switch to the next tab group (in Firefox 4)
Code: Select all
var evt = document.createEvent("KeyEvents");
evt.initKeyEvent(
"keypress",
true,
true,
null,
true, // holds Ctrl key
false, // holds Alt key
false, // holds Shift key
false, // holds Meta key
false, // presses a special key, @see http://mxr.mozilla.org/mozilla/source/dom/public/idl/events/nsIDOMKeyEvent.idl
"`".charCodeAt(0) // presses a normal key, e.g. "A".charCodeAt(0),
);
document.documentElement.dispatchEvent(evt);
Good luck all!
-
- Posts: 27
- Joined: March 23rd, 2011, 10:04 pm
Re: firegestures to control keyboard shortcuts
Any idea how to get ctrl+tab to operate properly? This is something I could never figure out. Sending the keypress event is easy enough (will immediately focus the next tab) but getting the thumbnail previews to stay open to toggle through them is something else...
-
- Posts: 31
- Joined: December 20th, 2010, 10:41 am
Re: firegestures to control keyboard shortcuts
As long as this thread was re-opened fairly recently, I thought I'd ask a question. Not being too bright I don't know much about this script stuff, but I'm trying to get FireGestures to send a key event of a simple "." (It opens the keyboard shortcuts at FastMail's webmail.) The following is what I have (based on trying to understand the information in this thread:
It doesn't seem to work. What did I do wrong ?
var evt = document.createEvent("KeyEvents");
evt.initKeyEvent(
"keypress",
true,
true,
null,
false, // holds Ctrl key
false, // holds Alt key
false, // holds Shift key
false, // holds Meta key
false, // presses a special key, @see http://mxr.mozilla.org/mozilla/source/d ... yEvent.idl
".".charCodeAt(0) // presses a normal key, e.g. "A".charCodeAt(0),
);
document.documentElement.dispatchEvent(evt);
It doesn't seem to work. What did I do wrong ?
-
- Posts: 78
- Joined: July 10th, 2004, 4:11 am
Re: firegestures to control keyboard shortcuts
Is it possible to create gestures specific to a web page?
I'm looking at creating gestures just for Google Reader, eg. a gesture to trigger Mark All As Read.
I'm looking at creating gestures just for Google Reader, eg. a gesture to trigger Mark All As Read.
-
- Posts: 78
- Joined: July 10th, 2004, 4:11 am
-
- New Member
- Posts: 1
- Joined: May 18th, 2011, 12:40 am
Re: firegestures to control keyboard shortcuts
It seems firegestures' script works on the chrome xul rather than the document itself (you can see it with alert(location.href);). So keys for Firefox (such as Ctrl-S for save) works but not for a website's keyboard shortcuts. Therefore you have to change 'document' to 'window.content.document' (saw it in the Copy Title script).
So I managed to send the keys 'Shift-n Shift-o' (open next subscription) to Google Reader with the following script:
0x4E is equivalent to the value of 'n'.charCodeAt(0) or 110 (see the Mozilla page for the codes). I tried using the number and/or formula, but having the 2 hex codes in the above script made it work. Hope it works for you!
So I managed to send the keys 'Shift-n Shift-o' (open next subscription) to Google Reader with the following script:
Code: Select all
var evt = window.content.document.createEvent("KeyEvents");
evt.initKeyEvent("keypress",true,true,null,false,false,true,false,0x4E,0x4E);
window.content.document.dispatchEvent(evt);
var evt2 = window.content.document.createEvent("KeyEvents");
evt2.initKeyEvent("keypress",true,true,null,false,false,true,false,0x4F,0x4F);
window.content.document.dispatchEvent(evt2);
0x4E is equivalent to the value of 'n'.charCodeAt(0) or 110 (see the Mozilla page for the codes). I tried using the number and/or formula, but having the 2 hex codes in the above script made it work. Hope it works for you!
-
- Posts: 31
- Joined: December 20th, 2010, 10:41 am
Re: firegestures to control keyboard shortcuts
Beautiful ! Thanks so much for your help !!
-
- Posts: 2
- Joined: September 12th, 2011, 9:44 am
Re: firegestures to control keyboard shortcuts
Just a thought. I don't know FF api terribly well, but bookmarklets use straight up javascript, which is quite handy for a ton of features/functions. There's some handy bookmarklet tools and creators out there. You can set a hotkey to any bookmarklet (google it) and have your gesture activate the the hotkey (the send key script above). This enables your bookmarklet to be cross browser compatible, and each browser has a way to activate bookmarklets with hotkeys and/or gestures.
travis_san:
As for control Tab, there's some scripts that access the firefox api directly. I'd suggest working with those:
http://www.xuldev.org/firegestures/getscripts.php
feather:
Yes, most certainly! It's always worth looking at the available scripts (link above) and see if they have code you can use. In one of them had some code that I modified.
First line gets the url. Second is a javascript function to see if substring is in string. If not, it'll return "-1"
Replace 'google' with whatever domain you're working with.
I have multiple domain specific features, so I used a bunch of if else statements.
const URL = window.content.location.href;
if(URL.indexOf('google')>=0){
// Run your domain specific code here
}
travis_san:
As for control Tab, there's some scripts that access the firefox api directly. I'd suggest working with those:
http://www.xuldev.org/firegestures/getscripts.php
feather:
Yes, most certainly! It's always worth looking at the available scripts (link above) and see if they have code you can use. In one of them had some code that I modified.
First line gets the url. Second is a javascript function to see if substring is in string. If not, it'll return "-1"
Replace 'google' with whatever domain you're working with.
I have multiple domain specific features, so I used a bunch of if else statements.
const URL = window.content.location.href;
if(URL.indexOf('google')>=0){
// Run your domain specific code here
}
-
- Posts: 11
- Joined: June 30th, 2009, 12:33 pm
Re: firegestures to control keyboard shortcuts
Can someone post what CTRL-ALT-TAB would be?
FireGestures.sendKeyEvent({ ctrl: true, altKey: true, key: "tab" });
doesn't seem to work. I am trying to get the following extension to work with Firegestures:
https://addons.mozilla.org/en-US/firefo ... b/?src=api
FireGestures.sendKeyEvent({ ctrl: true, altKey: true, key: "tab" });
doesn't seem to work. I am trying to get the following extension to work with Firegestures:
https://addons.mozilla.org/en-US/firefo ... b/?src=api
-
- Posts: 6429
- Joined: February 3rd, 2009, 6:29 pm
Re: firegestures to control keyboard shortcuts
@techer
Try running the following code with FireGestures, then use the shortcut to alert the Focus Last Tab command.
And there is no altKey property in the FireGestures API.
http://www.xuldev.org/firegestures/makescripts.php
Try running the following code with FireGestures, then use the shortcut to alert the Focus Last Tab command.
Code: Select all
function getCommand(event) {
window.removeEventListener("command", getCommand, true);
event.preventDefault();
event.stopPropagation();
alert(event.originalTarget.getAttribute("oncommand"));
}
window.addEventListener("command", getCommand, true);
And there is no altKey property in the FireGestures API.
http://www.xuldev.org/firegestures/makescripts.php
Code: Select all
FireGestures.sendKeyEvent({ ctrl: true, alt: true, keyCode: "DOM_VK_TAB" });
-
- Posts: 11
- Joined: June 30th, 2009, 12:33 pm
Re: firegestures to control keyboard shortcuts
Thanks, morat.
I just used the following code that you provided and it worked:
FireGestures.sendKeyEvent({ ctrl: true, alt: true, keyCode: "DOM_VK_TAB" });
I didn't use the other code. However, what would that do? Should I use it? What's the advantage?
function getCommand(event) {
window.removeEventListener("command", getCommand, true);
event.preventDefault();
event.stopPropagation();
alert(event.originalTarget.getAttribute("oncommand"));
}
window.addEventListener("command", getCommand, true);
I just used the following code that you provided and it worked:
FireGestures.sendKeyEvent({ ctrl: true, alt: true, keyCode: "DOM_VK_TAB" });
I didn't use the other code. However, what would that do? Should I use it? What's the advantage?
function getCommand(event) {
window.removeEventListener("command", getCommand, true);
event.preventDefault();
event.stopPropagation();
alert(event.originalTarget.getAttribute("oncommand"));
}
window.addEventListener("command", getCommand, true);
-
- Posts: 6429
- Joined: February 3rd, 2009, 6:29 pm
Re: firegestures to control keyboard shortcuts
@techer
The purpose of the code snippet is to easily extract commands.
Instructions:
1. open about:config
2. set devtools.chrome.enabled to true
3. tools > web developer > scratchpad
4. environment > browser
5. edit > paste (i.e. copy and paste code above)
6. execute > run
Examples:
7. page info menu item in tools menu
7. paste & go context menu item in location bar
7. ctrl+alt+tab shortcut
The trick does not work for all user interface elements.
You could also use the label of the menu item to execute the command.
Sometimes the FireGestures.sendKeyEvent function does not work.
viewtopic.php?f=38&t=2673197
The purpose of the code snippet is to easily extract commands.
Instructions:
1. open about:config
2. set devtools.chrome.enabled to true
3. tools > web developer > scratchpad
4. environment > browser
5. edit > paste (i.e. copy and paste code above)
6. execute > run
Examples:
7. page info menu item in tools menu
Code: Select all
BrowserPageInfo();
7. paste & go context menu item in location bar
Code: Select all
gURLBar.select();
goDoCommand("cmd_paste");
gURLBar.handleCommand();
7. ctrl+alt+tab shortcut
Code: Select all
focuslasttab.swap();
The trick does not work for all user interface elements.
You could also use the label of the menu item to execute the command.
Code: Select all
var label = "Focus Last Tab";
document.getElementsByAttribute("label", label)[0].doCommand();
techer wrote:What's the advantage?
Sometimes the FireGestures.sendKeyEvent function does not work.
viewtopic.php?f=38&t=2673197