event handler onkeyup, onkeydown - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

event handler onkeyup, onkeydown

pseudocoderpseudocoder Posts: 688Member ✭✭✭
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.

[code]
...


function handler(e) {

...
[/code]

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

Comments

  • leeeoleeeo Posts: 12Member
    : 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.
    :
    : [code]
    : ...
    :
    :
    : function handler(e) {
    :
    : ...
    : [/code]
    :
    : 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);
    }
  • pseudocoderpseudocoder Posts: 688Member ✭✭✭
    : : 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.
    : :
    : : [code]
    : : ...
    : :
    : :
    : : function handler(e) {
    : :
    : : ...
    : : [/code]
    : :
    : : 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.
Sign In or Register to comment.