/    Sign up×
Community /Pin to ProfileBookmark

Help with cross browser keypress issues..

Ok here is my problem, I need a script that will call a function when one of the arrow keys is pressed. The script I wrote works great in IE but I can’t seem to get it to function in Mozilla or Firefox. I would like to support as many browsers as possible but I am starting to think it’s going to be IE only for this projest ?…

Thanks in advance for any help below is the current script I am using.

<script type=”text/javascript”>
document.onkeyup = KeyCheck;

function KeyCheck()
{
var KeyID = event.keyCode;

switch(KeyID)
{
case 37:
parent.mapframe.moveImageLeft(‘MyPic’);
break;

case 38:
parent.mapframe.moveImageUp(‘MyPic’);
break;

case 39:
parent.mapframe.moveImageRight(‘MyPic’);
break;

case 40:
parent.mapframe.moveImageDown(‘MyPic’);
break;

}
}
</script>

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@EliteCGIauthorSep 17.2005 — http://www.webdeveloper.com/forum/showthread.php?t=79310[/QUOTE]

No offence Fang, but did you read my question? That thread has nothing to do with what I was asking. I am not trying to limit something in a form, I am trying to execute a function when someone hits an arrow key. It works in IE but not Firefox or Mozilla.
Copy linkTweet thisAlerts:
@FangSep 17.2005 — The post includes a method of returning the key pressed.
Copy linkTweet thisAlerts:
@EliteCGIauthorSep 17.2005 — I looked through the code and I tried a couple of things but I still can't get it to work with my code.

I simply need my script to catch the arrow keys and when one is pressed execute a function.

Basically when a user hits Up the Up function is called or Down and the down function is called.

If somebody could modify my script to function exactly like it does now but support Mozilla and firefox. It would be greatly appriciated.
Copy linkTweet thisAlerts:
@FangSep 17.2005 — document.onkeyup = KeyCheck;

function KeyCheck(e)
{
var KeyID =(window.event)? event.keyCode : e.which;

switch(KeyID)
.
.
.
Copy linkTweet thisAlerts:
@EliteCGIauthorSep 17.2005 — ? Worked perfectly, thanks for the help!!!
×

Success!

Help @EliteCGI 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.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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