views:

37

answers:

2

I'd like to add a feature to the awesome GleeBox project and it involves intercepting requests to create new tabs (so command-T on OS X). I know this sounds like a bad idea but bear in mind this is for an optional extension!

Anyway, is it possible to intercept a modified key-event that is used for a "system" function such as this?

A: 

If your write a keydown handler and inspect the event you get, there's an attribute called metaKey which indicates if the meta (command) key is down. You can probably use this to do what you want ... but you may be better off instead just using the T key or something like shift-T. Otherwise, you run the risk of irritating the user!

afshin
Yeah, I think you're probably right on reflection.
jkp
+1  A: 

Simply return false in the onkeydown event handler.

Be careful to ONLY do it if both keys are down though, not only on control and not only on t. That will mess up all other hotkeys the browser has.

I don't see why you would need ctrl+t though, that's one of the hotkeys in the browser that never should be blocked. (one of the main reasons people hate flash btw)

Ninja rhino
Hey: your advice got me close but it seems that the browser blocks overridding this shortcut. Interestingly I can catch and handle cmd-R (refresh) but not cmd-T. Still your answer was correct so the points go to you.
jkp