Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Or catch the key's event trigger with onfocus or onkeydown. That way even if they are pressed, nothing will happen.


sort by: page size:

It feels like having a predefined list of keys that are ignored is a "hack". Would a better solution be to simply wait until none of the _trigger_ keys were pressed?

E.g. if the sequence was "Ctrl" + "F8" then it would just ensure that neither Ctrl nor F8 were pressed.


probably:

    if (event.type === 'keypress') {
        event.preventDefault();
        doSomethingElse();   
    }

Yes it does. Just preventDefault() the keyDown event.

We don't use Keymaster, but our homebrew solution works the same way. You can solve the problem by adding an event to elements that you don't want to react that stops bubbling. Since those elements are focused when a key is pressed, the event for that element will be triggered first. Our form validation script adds this automatically. Problem solved.

I just disable it, I don't touch type particularly well and hitting it by accident never gives me what I want!

“No cameras on the keyboard please”

(Presses only one key)


You can handle the onblur event and use it to clear all pressed keys.

    onkeydown=function(event){if(event.key==="Enter"){mySubmit();}}
You are clearly overthinking the challenge.

Just don't hold the spacebar. {blink blink}

That's something I discovered the other day on my pc. At some point during the last year or so, I accidentally assigned a macro to the C key that did nothing but press the C key, so it was pretty much impossible to notice during normal use, except that holding it down behaved out of the ordinary.

It needs a `preventDefault` on the keypress events.

so keydown() instead of keyup()? Dragging my already-depressed-cursor off the button is my only out, you cant take that one away from me!

Keyup doesn't account for holding down keys either. It's keydown that is what you're after for that one.

No.

You could listen for the keydown, but you wouldn't hear it, so you may as well ignore what you can't hear.


Unfortunately, this only works unless you have a textfield focused or something similar that "consumes" your keyboard input. At least in my experience, it's quite unreliable.

Oh, I like that.

Anyway, I thought this only happens when you opt-in by enabling tabbing between all types of controls (the default is that only edit controls can get focus). What you're describing here, I think, is that the "Don't Save" button has focus, which is why spacebar activates it.

I hope this doesn't get nerffed. "Space => don't save, Enter => save" is part of my muscle memory now. Why would you enable focus on any control and then bang randomly on the keyboard anyway? If you aren't sure, leave the defaults as-is.


"hitting keys"

Stop hitting them then. Only use a laptop, and touch them lightly. Don't use a mouse, use a trackpad.


Yes you're right. I made a variable that tracked the current state of keyup keydown and could detect this special case.

By default holding down a key does not repeat it. I suspect you’ve probably turned that behavior off.
next

Legal | privacy