diff --git a/References/AutoHotkey.Interop.dll b/References/AutoHotkey.Interop.dll new file mode 100644 index 0000000000..b491cacb68 Binary files /dev/null and b/References/AutoHotkey.Interop.dll differ diff --git a/Wox.Infrastructure/Hotkey/AHKHotkey.cs b/Wox.Infrastructure/Hotkey/AHKHotkey.cs new file mode 100644 index 0000000000..01ade84903 --- /dev/null +++ b/Wox.Infrastructure/Hotkey/AHKHotkey.cs @@ -0,0 +1,18 @@ +using AutoHotkey.Interop; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Wox.Infrastructure.Hotkey +{ + public class AHKHotkey : IHotkey + { + public bool RegisterHotkey(string hotkey, Action action) + { + AutoHotkeyEngine ahk = AHKHotkeyEngineFactory.CreateOrGet("default"); + ahk.ExecRaw(string.Format("{0}::MsgBox, ssss!",hotkey)); + return true; + } + } +} diff --git a/Wox.Infrastructure/Hotkey/AHKHotkeyEngineFactory.cs b/Wox.Infrastructure/Hotkey/AHKHotkeyEngineFactory.cs new file mode 100644 index 0000000000..a812489b7a --- /dev/null +++ b/Wox.Infrastructure/Hotkey/AHKHotkeyEngineFactory.cs @@ -0,0 +1,51 @@ +using AutoHotkey.Interop; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Wox.Infrastructure.Hotkey +{ + internal class AHKHotkeyEngineFactory + { + private static List> engines = new List>(); + + public static AutoHotkeyEngine CreateOrGet(string name) + { + AutoHotkeyEngine engine = Get(name); + if (engine == null) + { + engine = Create(name); + } + return engine; + } + + public static AutoHotkeyEngine Create(string name) + { + var ahk = new AutoHotkey.Interop.AutoHotkeyEngine(); + engines.Add(new KeyValuePair(name, ahk)); + return ahk; + } + + public static AutoHotkeyEngine Get(string name) + { + var engine = engines.FirstOrDefault(o => o.Key == name); + if (engine.Key != null) + { + return engine.Value; + } + + return null; + } + + public static void Destroy(string name) + { + var engine = engines.FirstOrDefault(o => o.Key == name); + if (engine.Key != null) + { + engine.Value.Terminate(); + engines.Remove(engine); + } + } + } +} diff --git a/Wox.Infrastructure/Hotkey/IHotkey.cs b/Wox.Infrastructure/Hotkey/IHotkey.cs new file mode 100644 index 0000000000..849466aa00 --- /dev/null +++ b/Wox.Infrastructure/Hotkey/IHotkey.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Wox.Infrastructure.Hotkey +{ + interface IHotkey + { + bool RegisterHotkey(string hotkey, Action action); + } +} diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index ca13df96fb..8d19cd7bf5 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -37,6 +37,9 @@ false + + ..\References\AutoHotkey.Interop.dll + False @@ -58,6 +61,9 @@ + + + diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index e551a50dd1..b82943136e 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -243,6 +243,9 @@ namespace Wox public void SetHotkey(string hotkeyStr, EventHandler action) { + AHKHotkey ahk = new AHKHotkey(); + ahk.RegisterHotkey("#R",null); + return; var hotkey = new HotkeyModel(hotkeyStr); try { diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 586ba46bfe..11da8d8770 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -319,6 +319,7 @@ xcopy /Y /D /E $(SolutionDir)PythonHome\* $(TargetDir)PythonHome\ cd "$(TargetDir)" & del /s /q *.xml +if $(ConfigurationName) == Release ( cd "$(TargetDir)Plugins" & del /s /q NLog.dll cd "$(TargetDir)Plugins" & del /s /q NLog.config cd "$(TargetDir)Plugins" & del /s /q Wox.Plugin.pdb @@ -330,7 +331,8 @@ cd "$(TargetDir)Plugins" & del /s /q NAppUpdate.Framework.dll cd "$(TargetDir)Plugins" & del /s /q Wox.Infrastructure.dll cd "$(TargetDir)Plugins" & del /s /q Wox.Infrastructure.pdb cd "$(TargetDir)Plugins" & del /s /q Newtonsoft.Json.dll -cd "$(TargetDir)Plugins" & del /s /q WindowsInput.dll +cd "$(TargetDir)Plugins" & del /s /q WindowsInput.dll +)