How to check if a key (on the keyboard) is being held down?

in the past i've made a system that handles input like that

i record keyup and keydown events. for a given keycode, - on keydown pressed = Date.now() - on keyup, pressed = undefined - i have a separate game tick loop.
it checks how long the key has been held down.
then i can set a wait-time until hold registers or whatever.

at least last time i checked, modifier keys don't fire keyup's or keydown's. they can only be used as modifiers. so to make a WASD shooter game, i had to use C key for crouch instead of CTRL. minorly inconvenienced. luckily shift key for sprint is actually used like a modifier, so i could pick that up. otherwise shit would get weird

/r/webdev Thread