Fix crashes

Bug was found after investigation with MAGIC_VAL property
injection. Reassignment of keys` events pointers was
disrupted by ISR, resulting in burnt foreground context from
time to time. Also key value calculation was fixed.