From 79aebf06dce2dc9745bb2992d454d50a67f8f70f Mon Sep 17 00:00:00 2001 From: Francesca Frangipane Date: Wed, 6 Jun 2018 11:30:26 -0400 Subject: [PATCH] macOS: Fix alt and win keycodes (#552) * macOS: Generate LAlt/RAlt VirtualKeyCode * macOS: Correct RWin/LWin --- CHANGELOG.md | 2 ++ src/platform/macos/events_loop.rs | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c072fed..55af39fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - On X11, the environment variable `WINIT_HIDPI_FACTOR` has been added for overriding DPI factor. - On X11, enabling transparency no longer causes the window contents to flicker when resizing. - On X11, `with_override_redirect` now actually enables override redirect. +- macOS now generates `VirtualKeyCode::LAlt` and `VirtualKeyCode::RAlt` instead of `None` for both. +- On macOS, `VirtualKeyCode::RWin` and `VirtualKeyCode::LWin` are no longer switched. # Version 0.15.0 (2018-05-22) diff --git a/src/platform/macos/events_loop.rs b/src/platform/macos/events_loop.rs index 22c349dd..6b6d1c67 100644 --- a/src/platform/macos/events_loop.rs +++ b/src/platform/macos/events_loop.rs @@ -598,14 +598,14 @@ pub fn to_virtual_key_code(code: c_ushort) -> Option { 0x33 => events::VirtualKeyCode::Back, //0x34 => unkown, 0x35 => events::VirtualKeyCode::Escape, - 0x36 => events::VirtualKeyCode::RWin, - 0x37 => events::VirtualKeyCode::LWin, + 0x36 => events::VirtualKeyCode::LWin, + 0x37 => events::VirtualKeyCode::RWin, 0x38 => events::VirtualKeyCode::LShift, //0x39 => Caps lock, - //0x3a => Left alt, + 0x3a => events::VirtualKeyCode::LAlt, 0x3b => events::VirtualKeyCode::LControl, 0x3c => events::VirtualKeyCode::RShift, - //0x3d => Right alt, + 0x3d => events::VirtualKeyCode::RAlt, 0x3e => events::VirtualKeyCode::RControl, //0x3f => Fn key, //0x40 => F17 Key, @@ -695,7 +695,7 @@ unsafe fn modifier_event( keymask: NSEventModifierFlags, key_pressed: bool, ) -> Option { - if !key_pressed && NSEvent::modifierFlags(ns_event).contains(keymask) + if !key_pressed && NSEvent::modifierFlags(ns_event).contains(keymask) || key_pressed && !NSEvent::modifierFlags(ns_event).contains(keymask) { let state = ElementState::Released; let keycode = NSEvent::keyCode(ns_event);