Keycheck

1 view
Skip to first unread message

ddistelhorst

unread,
May 5, 2008, 5:12:01 PM5/5/08
to greasemonkey-users
I need to do a redirect to one of 3 different URLs. I current have 3
different scripts to do this but I have to manual enable one of them
and disable the other 2.

I'd like to make life easier and thought that using Keycheck() along
with a SWITCH statement might be the way to go...but I'm not sure how
to implement it.

Basically, I was to redirect to URL #1 if no key is pressed, redirect
to URL #2 if the CTRL key is pressed, or redirect to URL #3 if the ALT
key is pressed.

Any advice?

ddistelhorst

unread,
May 5, 2008, 5:36:17 PM5/5/08
to greasemonkey-users
I should have said keycode (not keycheck).

gollum

unread,
May 6, 2008, 7:59:42 AM5/6/08
to greasemonkey-users
find the links, add an event listener to the link, something like...

lnk.addEventListener( a, "mousedown",
function(e) {
if (e.altKey) {
"go somewhere";
} else if (e.ctrlKey) {
"go somewhere else";
} else {
"do the default";
}
}
, false);

http://www.w3.org/TR/DOM-Level-3-Events/events.html#Events-KeyboardEvent

ddistelhorst

unread,
May 6, 2008, 9:45:19 AM5/6/08
to greasemonkey-users
I'm still confused. There are no links that I need to look for. I also
don't understand why I would use mousedown. This is the rough idea of
what I want to do for a given URL that GM is watching for:

if (altKey) {
document.location.replace(/new-url-1/)
} else if (ctrlKey) {
document.location.replace(/new-url-2/)
} else {
document.location.replace(/new-url-3/)
};

Other than the correct syntax, what am I missing?

Anthony Lieuallen

unread,
May 6, 2008, 9:56:39 AM5/6/08
to greasemon...@googlegroups.com
On 5/6/2008 9:45 AM, ddistelhorst wrote:
> Other than the correct syntax, what am I missing?

In javascript, the only way to know if a modifier key is pressed is to
examine an event. It might be available as part of the load event, but
I've never tried doing such a thing, so I can't guarantee that.

Reply all
Reply to author
Forward
0 new messages