lordofduct Posted August 23, 2020 Share Posted August 23, 2020 (edited) It'd be nice if there was a way to hook into the events that occur in synergy. For example it'd be nice if we could hook into when a specific computer/screen receives/loses the mouse (basically at the same time the log signals "switch from 'pc1' to 'pc2'"). And when we hook into it we can run a batch/bash/shell script or something else like that. For me specifically I'd like an application to get focus/maximize when I've moused to another screen, and minimize when I leave the screen. But the ability to run any batch/bash/shell script would give the freedom to really hook into the host OS in any way possible. Just like with the 'hotkey', we could just have a different option in the hotkey being an event of some sort (exit/enter by pc name), and the actions just gets another entry in the window that runs a batch/bash/shell script. This could even integrate with hotkeys too letting us also use the hotkeys to run scripts as well. And maybe other events? Like server stop/start, client connect/disconnect, etc. Personally I'd only need them on the server... but it'd be cool if you could also hook into these events on clients as well (well, the events that make sense from the client side... exit/enter would, but like server stop/start isn't so much). Edited August 23, 2020 by lordofduct Quote Link to comment Share on other sites More sharing options...
lordofduct Posted August 26, 2020 Author Share Posted August 26, 2020 So in the mean time I came up with a hack way to get what I want. Since my server is a windows machine I wrote a simple service that monitors my log file. When it changes I grab the new text and process it. If the lines include the messages for a switch between computers, I grab out the from and to computers, and perform an action based on it: using System; using System.IO; using System.ServiceProcess; using System.Text.RegularExpressions; namespace SynergyScreenChangeMonitor { public partial class MonitorService : ServiceBase { #region Fields private FileSystemWatcher _watcher; private long _position; #endregion #region CONSTRUCTOR public MonitorService() { InitializeComponent(); } #endregion #region Properties public string FileToMonitor { get; set; } #endregion #region Methods protected override void OnStart(string[] args) { if(_watcher != null) { this.OnStop(); } if (!File.Exists(this.FileToMonitor)) return; using (var strm = new FileStream(this.FileToMonitor, FileMode.Open)) { _position = strm.Length - 1; } // Create a new FileSystemWatcher and set its properties. _watcher = new FileSystemWatcher(); _watcher.Path = Path.GetDirectoryName(this.FileToMonitor); /* Watch for changes in LastAccess and LastWrite times, and the renaming of files or directories. */ _watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; // Only watch text files. _watcher.Filter = Path.GetFileName(this.FileToMonitor); // Add event handlers. _watcher.Changed += OnChanged; _watcher.Created += OnChanged; _watcher.Deleted += OnChanged; // Begin watching. _watcher.EnableRaisingEvents = true; } protected override void OnStop() { if(_watcher != null) { _watcher.Dispose(); _watcher = null; } } private void OnChanged(object sender, FileSystemEventArgs e) { switch(e.ChangeType) { case WatcherChangeTypes.Created: case WatcherChangeTypes.Deleted: _position = 0; break; case WatcherChangeTypes.Changed: string txt = string.Empty; try { using (FileStream stream = File.Open(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var reader = new StreamReader(stream)) { reader.BaseStream.Position = Math.Min(_position, reader.BaseStream.Length - 1); txt = reader.ReadToEnd(); _position = reader.BaseStream.Position; } } catch (Exception) { } this.ProcessNewLines(txt ?? string.Empty); break; } } private void ProcessNewLines(string txt) { using (var reader = new StringReader(txt)) { string ln; while((ln = reader.ReadLine()) != null) { if (string.IsNullOrWhiteSpace(ln)) continue; var m = Regex.Match(ln, @"\[.*\] INFO\: switch from ""(?<from>.*)"" to ""(?<to>.*)"" at"); if(m.Success) { string from = m.Groups["from"].Value; string to = m.Groups["to"].Value; //DO STUFF - based on from/to } } } } internal void DebugStart() { OnStart(null); } #endregion } } Quote Link to comment Share on other sites More sharing options...
Totolicious Posted October 8, 2020 Share Posted October 8, 2020 +1 I would also like this Watching the log file seems like a nice workaround too. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.