Jump to content

How do I detect a keypress without using onkeypress inside of a form?


FalseProphet

Recommended Posts

wat..?

I currently have:

<div id="scene_input" onkeydown='evtKeyboard.KeyDown(event)' onkeyup="evtKeyboard.KeyUp(event)" onclick='evtMouse.GetMouseState(event)' style="width:100px; height:100px; border:1px solid #ff0000"></div>

None of the onkey events work. However, onclick does... In body, onkey events work just fine. However placing them inside of body is not a possibility for my current project.

 

I don't get what you mean by your post.. Using addEventListener() inside of a javascript script works for exactly what I described in my first post. However it it seems to pause setTimeout and setInterval for some reason.

What you said in your first post made it sound like you didn't want to use any event handlers at all, not that you simply didn't want them on the

.

 

What's the structure of your HTML and where can you make changes?

I'm not sure what you mean by structure. I'm trying to send keypresses to a canvas element.

My html document looks like this:

<!DOCTYPE HTML>
<HTML>

<HEAD>

	<script type="text/javascript" src="scripts/glib.js"></script>
	<script type="text/javascript" src="scripts/glib_common.js"></script>

</HEAD>

<BODY> <!--onload="init()" onkeydown="evtKeyboard.KeyDown(event)" onkeyup="evtKeyboard.KeyUp(event)" onclick="evtMouse.GetMouseState(event)"> -->
	<canvas id="scene" style="border:1px solid #ff0000; width:500px; height:500px;">
		Your browser does not support a Canvas element!
	</canvas>
	<div id="debug" style="position: relative; width:500px;height:200px; border:1px solid #0010ff"></div>

	<script>init();</script>

</BODY>

</HTML>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.