LM Remote KeyMap allows you to use C# code to extend its possibilities. The C# scripting engine enable access to the .Net Framework as well as native Win32 API. The C# scripting engine also enable to use the LM Remote KeyMap actions from your scripts through the LM Remote KeyMap object model.
The scripts can be used either for a remote button press or an event; the scripting engine is only available in the LM Remote KeyMap donator's edition.
Warning: the scripts allows total control over your computer. The scripts are usually running with the privileges of the LM Remote KeyMap desktop listener: usually a user privilege under Windows Vista / 7 with UAC protection. Though as scripts can use LM Remote KeyMap actions, they can use the "Launch Application" action and as such launch processes with elevated privileges. So a script could very well download an application from the Internet and launch it with administrator privileges. So you should only enable the scripting engine if you need it and only for a few application profiles.
Creating a script
To create a script, select the Script action. LM Remote KeyMap open the script editor preloaded with a script skeleton.
using System;
using System.Diagnostics;
using LMGestion.RemoteKeyMap.ObjectModel;public class Script : IRKMScript
{
//This is the main script function : return true to
//stop executing more actions after your script
public bool Execute(ref ActionChainContext currentContext)
{
currentContext.remoteKeyMap.WriteTrace(TraceLevel.Info,"Script Start");
//Write your code here
currentContext.remoteKeyMap.WriteTrace(TraceLevel.Info,"Script End");
return false;
}
}
A few explanations:
- using LMGestion.RemoteKeyMap.ObjectModel : this is the namespace containing all objects and classes definition needed for interfacing your script with LM Remote KeyMap. A LMGestion.RemoteKeyMap.ObjectModel.dll assembly is available (as well as documentation XML LMGestion.RemoteKeyMap.ObjectModel.XML) for you to edit scripts with the C# editor of your choice and make use of code autocompletion within the editor (autocompletion doesn't work in the LM RKM script editor)
- public class Script : IRKMScript : this is the main class for your script. This class (here named 'Script' must implement the IRKMScript interface)
- public bool Execute(ref ActionChainContext currentContext) : this is the main entry point of your script. This function is a member of the IRKMScript interface, so you must implement it. This funtion should return "false" if you want the actions following your script action to be executed, "true" otherwise.
Object Model
You can review the full documentation of the LM Remote KeyMap Object Model, but here are the most important objects to know about
ActionChainContext
The ActionChainContext is a value type that contains fields that describe the current action chain. The action chain is the list of actions LM Remote KeyMap is currently executing for an event or a remote button press.
When LM Remote KeyMap execute an action it always pass an ActionChainContext so that actions can exchange and retreive basic informations during their executions.
For instance the ActionChainContext contains a pointer to the main LM Remote KeyMap object, the current focused window, the current actions to be executed, the remote button that started the action chain, etc...
You'll often need to pass an ActionChainContext for using LM Remote KeyMap actions, usually you'll create a new one based on the one you received with the help of the Copy method of the ActionChainContext.
IRKMObject
The IRKMObject interface is a pointer to the main LM Remote KeyMap Object. You'll have to use this pointer to create LM Remote KeyMap action throuhg the CreateAction method. This pointer allows you to access the global context of LM Remote KeyMap throuhg an IContext interface pointer : the global context is like the ActionChainContext: ActionChainContext is the context for the current actions being executed, whereas the global context applies to LM Remote KeyMap as a whole. So you can store / retreive global variables into the global context through the indexer of the IContext interface.
Scripts Samples
Here is a script that makes use of the LM RKM OSD
using System;
using System.Diagnostics;
using LMGestion.RemoteKeyMap.ObjectModel;
public class Script : IRKMScript
{
public bool Execute(ref ActionChainContext currentContext)
{
currentContext.remoteKeyMap.WriteTrace(TraceLevel.Info,"Script Start");
//Get a LM Remote KeyMap Action
IAction action = currentContext.remoteKeyMap.CreateAction(ActionType.ShowOsd);
//Set up the action
((IShowOSDAction)action).Text = "Hello World !";
//Execute the action
action.Execute(ref currentContext);
currentContext.remoteKeyMap.WriteTrace(TraceLevel.Info,"Script End");
return false;
}
}
Here is a script that is using the blast raw action
using System;
using System.Diagnostics;
using LMGestion.RemoteKeyMap.ObjectModel;
public class Script : IRKMScript
{
//This is the main script function : return true to
//stop executing more actions after your script
public bool Execute(ref ActionChainContext currentContext)
{
currentContext.remoteKeyMap.WriteTrace(TraceLevel.Info,"Script Start");
IAction action = currentContext.remoteKeyMap.CreateAction(ActionType.BlastRaw);
((IBlastRawAction)action).DeviceID = "b5ab697b6eb74b45aeab4e024db9b176";
((IBlastRawAction)action).IRCode = "0000 006D 0022 0002 0156 00AC 0015 0016 0015 0041 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0041 0015 0041 0015 0041 0015 0016 0015 0016 0015 0041 0015 0041 0015 0041 0015 0041 0015 0016 0015 0041 0015 0016 0015 0016 0015 0041 0015 0016 0015 0016 0015 0016 0015 0041 0015 0016 0015 0041 0015 0041 0015 0016 0015 0041 0015 0041 0015 0041 0015 05F5 0156 0056 0015 0E47";
action.Execute(ref currentContext);
currentContext.remoteKeyMap.WriteTrace(TraceLevel.Info,"Script End");
return false;
}
}
Here is a script that do display a LM RKM Menu
using System;
using System.Diagnostics;
using LMGestion.RemoteKeyMap.ObjectModel;
public class Script : IRKMScript
{
//This is the main script function : return true to
//stop executing more actions after your script
public bool Execute(ref ActionChainContext currentContext)
{
currentContext.remoteKeyMap.WriteTrace(System.Diagnostics.TraceLevel.Info, "Script Start");
//Create a menu action
IAction action = currentContext.remoteKeyMap.CreateAction(ActionType.DisplayMenu);
//Set up the action
ActionChainContext newContext = new ActionChainContext();
newContext.Copy(currentContext);
//Create the menu action
LMGestion.RemoteKeyMap.ObjectModel.Action menuAction = ((IDisplayMenuAction)action).ToAction();
menuAction.menuEntries = new Menu[3];
menuAction.menuEntries[0].name = "Menu Entry 1";
//Assign actions to the menu entry
menuAction.menuEntries[0].menuActions = new LMGestion.RemoteKeyMap.ObjectModel.Action[1];
IAction volumeAction = currentContext.remoteKeyMap.CreateAction(ActionType.VolumeMute);
menuAction.menuEntries[0].menuActions[0] = ((IVolumeMuteAction)volumeAction).ToAction();
menuAction.menuEntries[1].name = "Menu Entry 2";
menuAction.menuEntries[2].name = "Menu Entry 3";
//Pass the menu action into the new context
newContext.currentActions = new LMGestion.RemoteKeyMap.ObjectModel.Action[1];
newContext.currentActions[0] = menuAction;
//Execute the menu
action.Execute(ref newContext);
currentContext.remoteKeyMap.WriteTrace(System.Diagnostics.TraceLevel.Info, "Script End");
return false;
}
}

