- Home /
Question by
Hannibal_Leo · May 08, 2017 at 05:40 PM ·
savecustom editor
[SOLVED] How to track CRTL + S in editor window?
Okay, I searched for an hour to solve this, time to ask questions:
I already tried to use: [MenuItem("InGameLists/SaveEditor %s")] - "%" is "CRTL", "s" is "S-Key" but this didn't work, then I searched everywhere and everybody just want to track the save function unity has, but I don't change things in the scene, I have my custom serialisation to use OOP features in a database and I want to save it with CRTL + S, but I cannot track those buttons somehow. Any ideas?
Comment
Answer by Hannibal_Leo · May 15, 2017 at 02:32 PM
Got it - after days of work
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class SREditorAutoSave {
bool crtlKeyDown = false;
public void AutoSave(Event e)
{
if (e.keyCode == KeyCode.LeftControl && e.type == EventType.KeyDown)
{
crtlKeyDown = true;
}
if (e.keyCode == KeyCode.LeftControl && e.type == EventType.KeyUp)
{
crtlKeyDown = false;
}
if (e.keyCode == KeyCode.S && crtlKeyDown)
{
Debug.Log("saved from crtl s");
SRSaveEditorDatabase.Save();
}
AutoSaveTimer();
}
double timer = 0;
void AutoSaveTimer()
{
if(EditorApplication.timeSinceStartup > timer)
{
timer = EditorApplication.timeSinceStartup + (double)(2 * 60); // 2 Minutes
SRSaveEditorDatabase.Save();
}
}
}
on every editor in my system I just use:
SREditorAutoSave saveEditorHelper = new SREditorAutoSave();
void OnGUI(){
//check event
Event e = Event.current;
saveEditorHelper.AutoSave(e);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612121553im_/https://answers.unity.com/themes/thub/images/avi.jpg)