X-keys editor to create JSON file

I have started working on a JSON schema to support the X-keys options that can be performed in PowerShell for each button. Originally I was thinking of doing this with an XML file, which would have worked fine, but the purpose of exercise is also to learn some new technology.

The JSON file format looks like this:

{
"keys": [
{
"Type": "Script",
"KeyID": 0,
"Command": " ",
"Script": " $me[0].Program=1",
"Caption": "Prog 1",
"Description": " Set Program bus to input 1"
},
{
"Type": "Script",
"KeyID": 1,
"Command": " ",
"Script": " $me[0].Preview=2",
"Caption": "Preview 2",
"Description": "Set Preview bus to input 2"
}
]
}

And the tool that saves you from having to create this in Notepad can be downloaded from here

It is very simple and just a temporary solution until my full WPF based host is ready (long term project so I’m not holding my breath, neither should you).

xkeysjsoneditor

The JSON file can be loaded in PowerShell and converted to a Hashtable with the following code…


$xk60File = ConvertFrom-Json (get-content "C:\Users\imorrish\OneDrive\PowerShell\V-ISE\test.json" -raw)
$xk60Commands = @{}
foreach($key in $xk60File.keys){
$xk60Commands.add($key.KeyID,$key.Script)
}
# this is the function called by the KeyDown event handler
function HandleXkey($key) {
if($xk24Commands.ContainsKey($key))
{
invoke-expression  $xk60Commands.Get_Item($key)
}
}

Note: if you want to store a file path or anything with a \ character, you have to double it up.
If you want to learn more about JSON, check out this article https://channel9.msdn.com/Series/Windows-Store-apps-for-Absolute-Beginners-with-C-/Part-11-Working-with-JSON-Data

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s