JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2061
Number of posts: 5164

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
event handler onkeyup, onkeydown Posted by pseudocoder on 22 Jul 2006 at 5:46 PM
I'm working with a perl script where I want to poll the keyboard; I've found snippits for the handler itself, but what I'm in the need of is a way to clear the event without having an alert box or submit button. I had the right combination that worked with both IE and Firefox, but I saved over it - long story. :(

Here's a basic sample of what I have now, but it doesn't work.

...
<head>
<script...>
function handler(e) { <!--
 the layer and document type of stuff

  document.write(keycode); // for output test
}

function clearit(e) { <!--
   return false;
}

document.onkeydown = handler;
document.onkeyup = clearit;
//--></script>
</head>
...


When it was *working,* I could press a key and get the code with each key press. I can't figure out what I did though to cancel the event.

Any ideas on what needs to be done.

TIA
Report
Re: event handler onkeyup, onkeydown Posted by leeeo on 4 Aug 2006 at 12:58 PM
: I'm working with a perl script where I want to poll the keyboard; I've found snippits for the handler itself, but what I'm in the need of is a way to clear the event without having an alert box or submit button. I had the right combination that worked with both IE and Firefox, but I saved over it - long story. :(
:
: Here's a basic sample of what I have now, but it doesn't work.
:
:
: ...
: <head>
: <script...>
: function handler(e) { <!--
:  the layer and document type of stuff
: 
:   document.write(keycode); // for output test
: }
: 
: function clearit(e) { <!--
:    return false;
: }
: 
: document.onkeydown = handler;
: document.onkeyup = clearit;
: //--></script>
: </head>
: ...
: 

:
: When it was *working,* I could press a key and get the code with each key press. I can't figure out what I did though to cancel the event.
:
: Any ideas on what needs to be done.
:
: TIA
:


First, for IE, you need to add the following into your handlers,

if(!e) e = window.event

Second, you want to use e.keyCode other than just keycode.
e.g.

function handler(e){
if (!e) e = window.event;
alert('You pressed ' + e.keyCode);
}
Report
Re: event handler onkeyup, onkeydown Posted by pseudocoder on 6 Aug 2006 at 12:52 PM
: : I'm working with a perl script where I want to poll the keyboard; I've found snippits for the handler itself, but what I'm in the need of is a way to clear the event without having an alert box or submit button. I had the right combination that worked with both IE and Firefox, but I saved over it - long story. :(
: :
: : Here's a basic sample of what I have now, but it doesn't work.
: :
: :
: : ...
: : <head>
: : <script...>
: : function handler(e) { <!--
: :  the layer and document type of stuff
: : 
: :   document.write(keycode); // for output test
: : }
: : 
: : function clearit(e) { <!--
: :    return false;
: : }
: : 
: : document.onkeydown = handler;
: : document.onkeyup = clearit;
: : //--></script>
: : </head>
: : ...
: : 

: :
: : When it was *working,* I could press a key and get the code with each key press. I can't figure out what I did though to cancel the event.
: :
: : Any ideas on what needs to be done.
: :
: : TIA
: :
:
:
: First, for IE, you need to add the following into your handlers,
:
: if(!e) e = window.event
:
: Second, you want to use e.keyCode other than just keycode.
: e.g.
:
: function handler(e){
: if (!e) e = window.event;
: alert('You pressed ' + e.keyCode);
: }
:


I'd all but forgotten this topic. :O

I *think* what I did before was to write the code to a cookie, and then read it back for printing. The goal was to poll the keyboard (arrow keys in particular) for image swapping. I needed to cancel the event so that the swap was transparent to the user... it was for a game.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.