FalseProphet Posted April 18, 2012 Share Posted April 18, 2012 As the title states, I want to detect when a keypress occurs but I don't want to use something like <body onkeydown="dothis(event)"></body> Is it possible? If so, how? Quote Link to comment https://forums.phpfreaks.com/topic/261214-how-do-i-detect-a-keypress-without-using-onkeypress-inside-of-a-form/ Share on other sites More sharing options...
requinix Posted April 19, 2012 Share Posted April 19, 2012 So... you want to detect keypresses without using anything that will let you detect keypresses? Quote Link to comment https://forums.phpfreaks.com/topic/261214-how-do-i-detect-a-keypress-without-using-onkeypress-inside-of-a-form/#findComment-1338641 Share on other sites More sharing options...
FalseProphet Posted April 19, 2012 Author Share Posted April 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261214-how-do-i-detect-a-keypress-without-using-onkeypress-inside-of-a-form/#findComment-1338643 Share on other sites More sharing options...
requinix Posted April 19, 2012 Share Posted April 19, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/261214-how-do-i-detect-a-keypress-without-using-onkeypress-inside-of-a-form/#findComment-1338646 Share on other sites More sharing options...
FalseProphet Posted April 19, 2012 Author Share Posted April 19, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/261214-how-do-i-detect-a-keypress-without-using-onkeypress-inside-of-a-form/#findComment-1338651 Share on other sites More sharing options...
FalseProphet Posted April 20, 2012 Author Share Posted April 20, 2012 Still seeking an answer for this. Any javascript gurus happen to have experience with this kind of thing? Quote Link to comment https://forums.phpfreaks.com/topic/261214-how-do-i-detect-a-keypress-without-using-onkeypress-inside-of-a-form/#findComment-1338935 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.