Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to prevent scrolling the browser window using arrow keys? 1

Status
Not open for further replies.

miraclemaker

Programmer
Oct 16, 2002
127
GB
I have a flash application embedded in a page which you use the cursor keys to control. The problem I'm having is that the page has a vertical scroll, and so whenever you push up / down on the cursor keys, it causes the page to scroll, despite the flash having focus.

Does anyone know of a way to prevent this?

Thanks.
 
There might be a way in Flash to capture "special" keyboard input... but I'd ask in the Flash form for that.

Failing that, you might try the JS forum for a JS workaround (if possible), or even a CSS workaround to disable the scrollbars (HTML/CSS forum).

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks Billy.

I did look into blocked the cursor presses with javascript, unfortunately this is not possible in IE as you don't get an event fired with the cursor keys are pressed, like you do for every other key.

I eventually discovered the poroblem was being caused due to the way we were adding the flash movie to the page - using javascript. I removed this and embedded the movie directly, then the problem went away.
 
this is not possible in IE as you don't get an event fired with the cursor keys are pressed, like you do for every other key.

Maybe you need to try a different key event - did you use onkeydown, onkeyup, or onkeypress? Give it a whirl, as they all behave differently.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I'm sure it's not possible. with onkeydown it is possible to register the cursor keys, but then consuming the event (returning false) doesn't have any effect.
 
I'm sure it's not possible.

Well why don't you try it and find out. I've given you more than enough to go on.

with onkeydown it is possible to register the cursor keys, but then consuming the event (returning false) doesn't have any effect.

So you have tried it, then? Well - that's odd, because the code below works perfectly for me in both IE 6/Win and Fx1.5.0.3/Win.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] lang="en" xml:lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<meta http-equiv="content-language" content="en" />
	<title>Cursor key test</title>
	<script type="text/javascript">
	<!--

		document.onkeydown = function(evt) {
			evt = (evt) ? evt : window.event;
			if (evt.keyCode >=37 && evt.keyCode <= 40) return(false);
		}

	//-->
	</script>
</head>
<body>
	<div>
		<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus egestas pulvinar leo. Vestibulum eu pede eget nulla venenatis viverra. Proin diam libero, rhoncus et, cursus eget, luctus ac, leo. Aenean at dui nec ipsum aliquam aliquam. Ut lacus. Nam dapibus massa a turpis. Donec eros justo, feugiat ut, faucibus eget, eleifend sed, turpis. Nulla commodo. Vestibulum sit amet lacus. Duis in ante non lacus egestas bibendum. Nunc euismod enim eu elit. Donec eros lorem, sodales et, mollis eget, sagittis vitae, nulla. Nam nec risus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus purus. Suspendisse semper pede.</p>
		<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce interdum pulvinar diam. Morbi ligula nisi, blandit quis, scelerisque ac, sodales iaculis, lectus. Praesent fringilla, sapien id commodo posuere, nisl dui porta mauris, venenatis sagittis erat tortor eu magna. Ut elementum commodo purus. Sed ullamcorper mollis orci. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus vel sapien. Aenean vitae tellus. Suspendisse augue. Nullam congue, augue in tempus sollicitudin, sem ligula porttitor sapien, ut aliquam leo erat eu diam. Aliquam erat volutpat.</p>
		<p>Donec aliquam interdum diam. Donec et nunc fringilla sem porttitor facilisis. Etiam neque tellus, auctor sed, tincidunt sed, rutrum nec, neque. Donec accumsan faucibus quam. Etiam at libero in nisi placerat pretium. Vestibulum velit metus, lacinia sit amet, mattis at, posuere sit amet, nunc. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam erat volutpat. Aenean justo augue, dignissim sed, laoreet sed, imperdiet sed, arcu. Morbi vestibulum tellus sed justo. Fusce nisi. Maecenas vitae risus. In hac habitasse platea dictumst. Nulla facilisi. Aliquam gravida, magna in tempor interdum, mi mauris blandit sapien, vitae auctor lorem arcu bibendum est. Quisque id nibh. Cras ultrices eros pretium sapien. Proin eros libero, pretium quis, sollicitudin varius, dapibus sollicitudin, justo.</p>
		<p>Sed fermentum ultrices sem. Integer in arcu. Nam libero. Curabitur eu sem. Pellentesque rutrum ligula sit amet lacus. Curabitur semper neque eget turpis accumsan aliquet. Integer vestibulum, lorem sit amet lacinia fermentum, augue urna sodales libero, eu venenatis massa leo a dui. Proin viverra pharetra enim. Duis tempus aliquet pede. In mauris.</p>
		<p>Aenean nec tellus eget velit dignissim gravida. Nunc viverra, magna ac aliquam tempor, felis dui bibendum eros, quis consequat sapien pede sit amet leo. Mauris fermentum quam mattis mi. Etiam erat nibh, semper eu, luctus vitae, venenatis at, nunc. Sed euismod ipsum sed augue. Pellentesque iaculis fermentum diam. Nulla laoreet porta turpis. Sed rutrum. Nunc nunc ipsum, dapibus a, ornare non, scelerisque tincidunt, lorem. Nullam eget pede</p>
	</div>
</body>
</html>

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I did try it without success, you've just shown me wrong! Thanks Dan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top