Totenmaske, I have an answer for this. As you pointed out, it's because the raw keyboard input does not correspond to the values specified in keys.sh. Before performing your event checking, make this kernel call:
MapKeyToDir(pEvent)
Then your code should work properly.
This will translate the raw keyboard input into the key constants specified in keys.sh (KEY_UP, KEY_DOWN, etc). I'm guessing that this call exists so that the same key codes work regardless of which OS the SCI VM is running on. So the implementation of the VM on different OS's perform a different key translation in the MapKeyToDir call, but the SCI code never needs to change.