MATLAB: How to use a 5 button mouse to navigate through a Simulink model

mousenavigationshortcutsimulinksl_customizations

I use the back and forward buttons of my mouse to navigate internet browsers. Can I do the same with Simulink models? Is there a way to configure my mouse so that the back button either goes up a level in a Simulink model?

Best Answer

By default, Simulink uses Escape (ESC) as the keyboard shortcut for going up a level in a model. If you would like to use a 5 button mouse for Simulink navigation, try one of the two methods.
*A) Custom Simulink Hotkey and Mouse Binding *
1. First, create a custom shortcut in Simulink. Start by creating a .m file with name 'sl_customization.m'. This will be used to create your custom shortcut for Simulink.
function sl_customization(cm)
cm.addCustomMenuFcn('Simulink:ToolsMenu', @getMyMenuItems);
end
function schemaFcns = getMyMenuItems(~)
schemaFcns = {@createBO};
end
function schema = createBO(~)
schema = sl_action_schema;
schema.label = 'Go to Parent';
schema.statustip = 'Go to Parent System';
schema.accelerator = 'Ctrl+Shift+u';
schema.callback = @createBOcb;
end
function createBOcb(~)
parentsystem = get_param(gcs, 'Parent');
if parentsystem ~= ""
open_system(get_param(gcs, 'Parent'));
end
end
In the function shown above, "open_system(get_param(gcs, 'Parent'))" opens up the parent system and "schema.accelerator = 'Ctrl+Shift+u';" sets the keyboard shortcut.
2. Save and add the containing folder to MATLAB path. Right click parent folder -> Add to Path -> Selected Folders
3. Run 'sl_refresh_customizations' on MATLAB Command Window. This will refresh Simulink customizations and add the custom shortcut. To remove the shortcut, simply remove the folder from MATLAB path and refresh customizations again.
>> sl_refresh_customizations
4. For reference on creating custom shortcuts in Simulink, please refer to the following resources:
5. After completing steps 1-4, you can optionally remap the mouse's back button to the shortcut you just created. The remapping software and method will be different for the device and setup you are using. Please refer to the correct documentation for the device you are using.
6. In short, you will need to re-assign the mouse's back button to the 'CTRL+SHIFT+U' keyboard shortcut you just created in Simulink. If possible, you can specify the remapping to only apply when MATLAB is the active application (in case you do not want the same shortcut to apply to other applications.
*B) Default Simulink Hotkey and AutoHotKey *
1. Alternatively, you can use AutoHotKey to automate the keyboard shortcut operation. AutoHotKey is a free, open-source software for automating repetitive keyboard tasks. For more information, refer to the website below:
2. Write an AutoHotKey script to use Simulink's default hotkeys. An example script is shown below.
;------------------------------------------------------
; This macro runs while Simulink is running and it allows
; 5 button functionality in Simulink.
; back button : go up a level
; front button : look under mask
; some additional options for other functionality...
;-----------------------------------------------------
#IfWinActive, ahk_class Qt5QWindowIcon ; when Simulink is open
xbutton1::escape
xbutton2::send {click}^u{enter}
+xbutton1::send {click}^l
+xbutton2::send {click}{alt}em
^xbutton1::^c
^xbutton2::^v
^wheelup::send r
^wheeldown::send v
^mbutton::send 1
2. The first line of the script which says '#IfWinActive...' activates hotkey only when Simulink is open. The forward button is configured for 'CTRL+U' which looks under a block mask in Simulink.
3. Once the script is written, open AutoHotKey and run the script to start using the shortcuts.