now automatically reading bindings on VA start and change of bindED.layout#

This commit is contained in:
alterNERDtive 2020-11-08 21:12:00 +01:00
parent 78124a42e3
commit 20c12007bc
3 changed files with 37 additions and 12 deletions

View file

@ -19,10 +19,12 @@ should basically never be used anyway.
## Added
* After the initial `loadbinds` invocation the plugin will monitor the bindings
* Bindings are now automagically read when VoiceAttack loads and when
`bindED.layout#` is changed.
* After the initial reading of bindings the plugin will monitor the bindings
directory for changes to a) the `StartPreset.start` file (preset has changed)
and b) the binds file(s) corresponding to the current preset. Changes are
automatically detected.
automatically applied.
* The `listbinds` context will set the text variable `~bindED.bindsList` to a
list of bindings present in the current bindings file. See README for details.
(#1).

View file

@ -15,10 +15,14 @@ details).
### Reading Bindings into VoiceAttack
Invoke the `loadbinds` plugin context. That will populate a bunch of variables
named `ed<name in the bindings file>` for you that you can use in commands
instead of hard-wiring key presses, enabling you to share profiles with other
players more easily.
You dont have to do anything! When VoiceAttack loads, bindED will automatically
detect your bindings. It will also keep a watchful eye on Elites bindings
folder and reload them when there is a change!
If something goes awry, you can still manually call the `loadbinds` plugin
context to force a refresh.
If you are not using a US QWERTY keyboard layout, see below.
### Saving the List of Variables
@ -58,15 +62,16 @@ that information will be incorrect for any symbols that are on a different key
than they are on the US layout.
I have added the option to use maps for other keyboard layouts. In order to do
so you will have to set a text variable in VoiceAttack called `bindED.layout` to
the layout you want to use before invoking the plugin. If the variable is not
so you will have to set a text variable in VoiceAttack called `bindED.layout#`
to the layout you want to use. BindED will be notified of the variable changing
and reload your bindings with the appropriate key map. If the variable is not
set it will defaut to “en-us”, leaving the original behaviour intact.
I have included a map file for [Neo2](https://neo-layout.org)
(`EDMap-de-neo2.txt`) which is the layout that I am using personally. If you are
on a different layout, you will have to create a corresponding map file yourself
or prod me to add it. E.g. for the french AZERTY it would be `EDMap-fr-fr.text`
and set `bindED.layout` to “fr-fr”. For US Dvorak, `EDmap-en-us-dvorak` and
and set `bindED.layout#` to “fr-fr”. For US Dvorak, `EDmap-en-us-dvorak` and
“en-us-dvorak”. You can see where this is going.
For more information on [creating new supported keyboard layouts see the

View file

@ -31,7 +31,17 @@ namespace bindEDplugin
public static void VA_Init1(dynamic vaProxy)
{
_VA = vaProxy;
_pluginPath = Path.GetDirectoryName(vaProxy.PluginPath());
_VA.TextVariableChanged += new Action<string, string, string, Guid?>(TextVariableChanged);
_pluginPath = Path.GetDirectoryName(_VA.PluginPath());
try
{
LoadBinds("en-us");
}
catch (Exception e)
{
LogError(e.Message);
}
}
public static void VA_Invoke1(dynamic vaProxy)
@ -40,7 +50,7 @@ namespace bindEDplugin
try
{
string context = _VA.Context.ToLower();
string layout = _VA.GetText("bindED.layout") ?? "en-us";
string layout = _VA.GetText("bindED.layout#") ?? "en-us";
if (context == "listbinds")
{
ListBinds(layout, _VA.GetText("bindED.separator") ?? "\r\n");
@ -58,7 +68,6 @@ namespace bindEDplugin
catch (Exception e)
{
LogError(e.Message);
return;
}
}
@ -66,6 +75,15 @@ namespace bindEDplugin
public static void VA_Exit1(dynamic vaProxy) { }
public static void TextVariableChanged(string name, string from, string to, Guid? internalID)
{
if (name.Equals("bindED.layout#"))
{
LogInfo($"Keyboard layout changed to '{to}', reloading …");
LoadBinds(to);
}
}
private static void LogError(string message)
{
_VA!.WriteToLog($"ERROR | bindED: {message}", "red");