From 01cb8e59e3c45e2efb155a5e85b74cb3b110f332 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Thu, 26 Jul 2018 01:36:33 +0800 Subject: [PATCH] Fix key state on MacOS (#610) --- CHANGELOG.md | 1 + src/platform/macos/events_loop.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e6c4bfd..28ed76be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +- On MacOS, the key state for modifiers key events is now properly set. - On iOS, the view is now set correctly. This makes it possible to render things (instead of being stuck on a black screen), and touch events work again. - Added NetBSD support. diff --git a/src/platform/macos/events_loop.rs b/src/platform/macos/events_loop.rs index e9f03ea0..3c893cdd 100644 --- a/src/platform/macos/events_loop.rs +++ b/src/platform/macos/events_loop.rs @@ -674,11 +674,15 @@ pub fn event_mods(event: cocoa::base::id) -> ModifiersState { unsafe fn modifier_event( ns_event: cocoa::base::id, keymask: NSEventModifierFlags, - key_pressed: bool, + was_key_pressed: bool, ) -> Option { - if !key_pressed && NSEvent::modifierFlags(ns_event).contains(keymask) - || key_pressed && !NSEvent::modifierFlags(ns_event).contains(keymask) { - let state = ElementState::Released; + if !was_key_pressed && NSEvent::modifierFlags(ns_event).contains(keymask) + || was_key_pressed && !NSEvent::modifierFlags(ns_event).contains(keymask) { + let state = if was_key_pressed { + ElementState::Released + } else { + ElementState::Pressed + }; let keycode = NSEvent::keyCode(ns_event); let scancode = keycode as u32; let virtual_keycode = to_virtual_key_code(keycode);