Hello,
I am trying to implement editor shortcut so that I can invoke my Editor Utility Widget, but I am stuck at the shortcut part.
This is what I came up with, based on the Python documentation, which should theoretically work, but there is an issue with unreal.ScriptingCommandInfo, it doesn’t seem to be exposed to python in the unreal.py (Error: AttributeError: module 'unreal' has no attribute 'ScriptingCommandInfo').
Based on the documentation here, I would expect to be able to use this class, am I misunderstanding something, or is this issue on the API side? I am on 5.4.
https://dev.epicgames.com/documentation/en-us/unreal-engine/python-api/class/ScriptingCommandInfo?application_version=5.4#unreal.ScriptingCommandInfo
import unreal
def register_shortcut():
editor_commands = unreal.get_editor_subsystem(unreal.LevelSequenceEditorSubsystem)
# Function to be executed when shortcut is pressed
def on_shortcut_pressed():
unreal.log("Ctrl+J was pressed!")
input_chord = unreal.InputChord()
input_chord.ctrl = True # Enable Ctrl modifier
# input_chord.shift = False
# input_chord.alt = False
chord_key = unreal.Key()
chord_key.set_editor_property("key_name", "J") # Get the key object
print(chord_key.get_editor_property("key_name")) # Get the key object
input_chord.key = chord_key # The main key to trigger the shortcut
scripting_command_info = unreal.ScriptingCommandInfo()
scripting_command_info.name = "PythonCommand.CustomShortcut"
scripting_command_info.label = "Custom Ctrl+J Shortcut"
scripting_command_info.description = "Executes custom functionality when Ctrl+J is pressed"
scripting_command_info.input_chord = input_chord
# Register the command
editor_commands.register_command(
command_info=scripting_command_info,
execute_command=on_shortcut_pressed,
default_desc="Custom Ctrl+J Shortcut",
help_text="Executes custom functionality when Ctrl+J is pressed",
)
# Call the function to register the shortcut
register_shortcut()
If this is incorrect approach for registering shortcuts, I would appreciate hints for the alternative.