Add autohotkey

This commit is contained in:
qianlifeng 2015-01-29 18:26:50 +08:00
parent 36ce0c8271
commit 2b1e343186
7 changed files with 93 additions and 1 deletions

Binary file not shown.

View File

@ -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;
}
}
}

View File

@ -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<KeyValuePair<string, AutoHotkeyEngine>> engines = new List<KeyValuePair<string, AutoHotkeyEngine>>();
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<string, AutoHotkeyEngine>(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);
}
}
}
}

View File

@ -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);
}
}

View File

@ -37,6 +37,9 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoHotkey.Interop">
<HintPath>..\References\AutoHotkey.Interop.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
@ -58,6 +61,9 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Hotkey\AHKHotkey.cs" />
<Compile Include="Hotkey\AHKHotkeyEngineFactory.cs" />
<Compile Include="Hotkey\IHotkey.cs" />
<Compile Include="Hotkey\InterceptKeys.cs" />
<Compile Include="Hotkey\KeyEvent.cs" />
<Compile Include="Logger\Log.cs" />

View File

@ -243,6 +243,9 @@ namespace Wox
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
{
AHKHotkey ahk = new AHKHotkey();
ahk.RegisterHotkey("#R",null);
return;
var hotkey = new HotkeyModel(hotkeyStr);
try
{

View File

@ -319,6 +319,7 @@ xcopy /Y /D /E $(SolutionDir)PythonHome\* $(TargetDir)PythonHome\
cd "$(TargetDir)" &amp; del /s /q *.xml
if $(ConfigurationName) == Release (
cd "$(TargetDir)Plugins" &amp; del /s /q NLog.dll
cd "$(TargetDir)Plugins" &amp; del /s /q NLog.config
cd "$(TargetDir)Plugins" &amp; del /s /q Wox.Plugin.pdb
@ -330,7 +331,8 @@ cd "$(TargetDir)Plugins" &amp; del /s /q NAppUpdate.Framework.dll
cd "$(TargetDir)Plugins" &amp; del /s /q Wox.Infrastructure.dll
cd "$(TargetDir)Plugins" &amp; del /s /q Wox.Infrastructure.pdb
cd "$(TargetDir)Plugins" &amp; del /s /q Newtonsoft.Json.dll
cd "$(TargetDir)Plugins" &amp; del /s /q WindowsInput.dll</PostBuildEvent>
cd "$(TargetDir)Plugins" &amp; del /s /q WindowsInput.dll
)</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.