Fix handling of modifier keys on macOS