Skip to content

Hotkeys don't work on macos #890

Open

Description

@Ughuuu

Description

When pressing ctrl + s to save the scene, or pressing ctrl + c or ctrl + v, hotkeys don't seem to work.

To Reproduce

Steps to reproduce the behavior:

  1. Download Fyrox, create a new project, try to press ctrl + s to save.

Expected behavior

Hotkeys work. For this, on macOS at least, I think an edit menu has to be created, eg. Safari:

Image

The menu has to be on the top of the window:

Image

Eg. in Godot:

Image

Activity

  1. Ughuuu commented on Feb 10, 2026

    @Ughuuu
    ContributorAuthor

    The code for it should be something like:

    #[cfg(target_os = "macos")]
    fn ensure_macos_edit_menu() {
        use cocoa::appkit::{NSApp, NSApplication, NSEventModifierFlags, NSMenu, NSMenuItem};
        use cocoa::base::{id, nil};
        use cocoa::foundation::NSString;
        use objc::runtime::Sel;
        use std::ptr;
    
        INIT_MACOS_EDIT_MENU.call_once(|| unsafe {
            let app = NSApp();
            if app == nil {
                return;
            }
    
            let main_menu = app.mainMenu();
            if main_menu == nil {
                return;
            }
    
            let edit_lookup = NSString::alloc(nil).init_str("Edit");
            let existing: id = objc::msg_send![main_menu, itemWithTitle: edit_lookup];
            if existing != nil {
                return;
            }
    
            let edit_title = NSString::alloc(nil).init_str("Edit");
            let edit_item = NSMenuItem::alloc(nil)
                .initWithTitle_action_keyEquivalent_(
                    edit_title,
                    Sel::from_ptr(ptr::null()),
                    NSString::alloc(nil).init_str(""),
                );
            edit_item.setSubmenu_(NSMenu::alloc(nil).initWithTitle_(NSString::alloc(nil).init_str("Edit")));
            main_menu.addItem_(edit_item);
    
            let edit_menu: id = objc::msg_send![edit_item, submenu];
            if edit_menu == nil {
                return;
            }
    
            add_standard_edit_item(edit_menu, "Undo", objc::sel!(undo:), "z", NSEventModifierFlags::NSCommandKeyMask);
            add_standard_edit_item(edit_menu, "Redo", objc::sel!(redo:), "Z", NSEventModifierFlags::NSCommandKeyMask | NSEventModifierFlags::NSShiftKeyMask);
            edit_menu.addItem_(NSMenuItem::separatorItem(nil));
            add_standard_edit_item(edit_menu, "Cut", objc::sel!(cut:), "x", NSEventModifierFlags::NSCommandKeyMask);
            add_standard_edit_item(edit_menu, "Copy", objc::sel!(copy:), "c", NSEventModifierFlags::NSCommandKeyMask);
            add_standard_edit_item(edit_menu, "Paste", objc::sel!(paste:), "v", NSEventModifierFlags::NSCommandKeyMask);
            //add_standard_edit_item(edit_menu, "Select All", objc::sel!(selectAll:), "a", NSEventModifierFlags::NSCommandKeyMask);
        });
    }
    
    #[cfg(target_os = "macos")]
    unsafe fn add_standard_edit_item(menu: cocoa::base::id, title: &str, selector: objc::runtime::Sel, key: &str, modifiers: cocoa::appkit::NSEventModifierFlags) {
        use cocoa::appkit::{NSMenu, NSMenuItem};
        use cocoa::base::nil;
        use cocoa::foundation::NSString;
    
        let item = NSMenuItem::alloc(nil)
            .initWithTitle_action_keyEquivalent_(
                NSString::alloc(nil).init_str(title),
                selector,
                NSString::alloc(nil).init_str(key),
            );
        item.setTarget_(nil);
        item.setKeyEquivalentModifierMask_(modifiers);
        menu.addItem_(item);
    }

    with Cargo.toml:

    [target.'cfg(target_os = "macos")'.dependencies]
    cocoa = "0.25"
    objc = "0.2"
  2. Ughuuu commented on Feb 10, 2026

    @Ughuuu
    ContributorAuthor

    It seems the hotkeys do work, or some of them, but they are ctrl + .. instead of cmd + ... (on macOS users expect the hotkeys to be with cmd for some things, but not all)

  3. mrDIMAS commented on Feb 14, 2026

    @mrDIMAS
    Member

    You can reconfigure hot keys in the editor settings. As a solution for mac in general, there could be a platform dependant modifier - for mac it would be cmd, and for other platforms ctrl.

  4. Ughuuu commented on Feb 14, 2026

    @Ughuuu
    ContributorAuthor

    Wanted to implement this, but wasn't 100% sure of the approach. Right now the hotkeys are ctrl+<> on all platforms. Should it just be a static function that changes that string based on platform?

  5. mrDIMAS commented on Feb 14, 2026

    @mrDIMAS
    Member

    I think you can change impl Default for KeyBindings and add there conditional compilation for desired keyboard modifier and change HotKey::ctrl_key to HotKey::key_with_modifiers where the key remains the same, but the modifiers differ depending on the platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions