Files
Artemis/Artemis/Artemis/Profiles/Lua/Modules/LuaKeyboardModule.cs
T
SpoinkyNL 6b3294ff7d LUA refactor
LUA is made up out of modules now
Added DI to LUA
Added GetKeyPosition to keyboard module
Cleaned up event arguments (see wiki)
Made all internal classes public since Artemis isn't a library anyway
Added DI convention based bindings
2016-12-25 14:27:56 +01:00

49 lines
1.5 KiB
C#

using System;
using System.Diagnostics;
using System.Windows.Forms;
using Artemis.DeviceProviders;
using Artemis.Managers;
using MoonSharp.Interpreter;
namespace Artemis.Profiles.Lua.Modules
{
[MoonSharpUserData]
public class LuaKeyboardModule : LuaModule
{
private readonly KeyboardProvider _keyboardProvider;
public LuaKeyboardModule(LuaManager luaManager) : base(luaManager)
{
_keyboardProvider = luaManager.KeyboardProvider;
// Register the KeyMatch type for usage in GetKeyPosition
UserData.RegisterType(typeof(KeyMatch));
}
public override string ModuleName => "Keyboard";
public string Name => _keyboardProvider.Name;
public string Slug => _keyboardProvider.Slug;
public int Width => _keyboardProvider.Width;
public int Height => _keyboardProvider.Height;
public void PressKeys(string keys)
{
SendKeys.SendWait(keys);
}
public KeyMatch? GetKeyPosition(string key)
{
// Convert string to Keys enum, I'm not sure if built-in enums can be converted automatically
try
{
var keyEnum = (Keys)Enum.Parse(typeof(Keys), key);
return _keyboardProvider.GetKeyPosition(keyEnum);
}
catch (ArgumentException)
{
throw new ScriptRuntimeException($"Key '{key}' not found");
}
}
}
}