macosx_events: DRY up key lookup over dictionary

Two methods duplicated very similar behaviour. Extract method with the common
behaviour.