Protect mod with a mutex

The reason I'm not using defer mutex.Unlock() here is because I don't
want to keep the mutex around while handleKeyEvent() is being
processed.