/    Sign up×
Community /Pin to ProfileBookmark

Overriding Safari and Opera keyboard shortcuts

I’m in the middle of developing an entirely javascript-based sudoku game. I developed it mostly while working with firefox on windows, and figured that once I got it working without bugs in firefox, I’d make it work in Safari, Opera, IE, etc.

So far, everything’s gone great (I haven’t started making it work in IE yet), except for one little thing. The game makes extensive use of keyboard shortcuts. Particularly, pressing CTRL + NumKey toggles a penciled-in mark in the currently selected space and CTRL + ArrowKey moves to the next un-filled space in the direction indicated. These both work just fine in every browser, with two exceptions: Opera doesn’t handle the CTRL + ArrowKey correctly (it does what I want it to do but still does the application-specific behavior even though I’ve preventedDefault), and Safari doesn’t handle CMD + NumKey right (the keypress handler just never fires at all for these key combinations!). The funny thing is, in the Safari case, CTRL + NumKey does just what I want it to, and CMD + – (another key command) works just fine–it’s just that [I]cmd[/I] + NumKey doesn’t work.

My question is, is there a way to use those key-commands in these programs? I’ve looked on the internet but really can’t find anything, and I’ve gotten to the point where I’ve run out of ideas. I’m doing everything available to cancel the event in Opera, but those pesky CTRL + ArrowKeys just keep on bubbling up and being acted upon by the application no matter what.

I know probably the best way to avoid these problems is just to not use these particularly keyboard shortcuts, but if there’s a way to keep using them in Safari and Opera, I really want to. I also know that it’s bad style to make keyboard shortcuts that people have come to rely on do something different when your page is loaded.

For reference, the page in question is [URL=http://people.fas.harvard.edu/~jkomoros/sudoku/index.html]here[/URL], although as a word of warning, the code is a MESS — that’s what I get for developing this piece-meal over the course of a month whenever I could find time between writing papers and class. Not only that, but also as I went along I came up with and implemented new features I hadn’t planned on before, so the code got pretty unwieldy. I’m planning on cleaning up all the behind-the-scenes code once I get the thing totally feature complete. I’ve also got a page-long list of things I still want to implement/fix, so it’s definitely nowhere near done right now.

Thanks for your help!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@felgallApr 29.2006 — Well anything that the browser interprets as a command that the browser expects to act on doesn't get passed to the web page so most if not all of those short cuts will never send anything as far as the web page and so the web page will have no way to tell that they were used. The only keys that you can guarantee will get to the web page are the regular keys on the keyboard without the CTRL or ALT key being pressed.

Even with IE or Firefox the CTRL keys may be assigned as shortcuts within the Operating System and never even get to the browser for the browser to even consider passing them to the page.
×

Success!

Help @jkomoros spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...