mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Add autohotkey
This commit is contained in:
18
Wox.Infrastructure/Hotkey/AHKHotkey.cs
Normal file
18
Wox.Infrastructure/Hotkey/AHKHotkey.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
51
Wox.Infrastructure/Hotkey/AHKHotkeyEngineFactory.cs
Normal file
51
Wox.Infrastructure/Hotkey/AHKHotkeyEngineFactory.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Wox.Infrastructure/Hotkey/IHotkey.cs
Normal file
12
Wox.Infrastructure/Hotkey/IHotkey.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
|
||||
Reference in New Issue
Block a user