Fixed incorrect modifier keys handling on macOS (cherry-picked from commit 45a58b7882a253db29b1b1393bc2a1fe030d5955)