(How to) Logitech Keyboard G-Key Sends JSON Using Powershell
Posted: Friday 24 June 2016 0:33
I am a gamer and I have this setup that has a LED strip below my desk and I recently build Ambilight behind my monitors, both lights are on a switch that can be controlled with Domoticz. I have a Logitech keyboard (G110) that has configurable keys (G-Keys) on it, and I thought that it would be nice to use this G-keys to turn my lights on and off, depending on if I am gaming (Ambilight On) or just derping around (LED Strip On).
I came up with the following solution:
(disclaimer: this solution enables PowerShell commands to be executed on your computers and MIGHT expose you to security risks, so use at your own risk)

How did I do this:
open your favorite text editor and create a PowerShell script (is made 4)

The script contains the following code: (change your ip address and the idx number to your situation, also this example is to turn the switch On, you can also use the Off command)
Save the file(s) at a location on your pc
Be sure to save it as a PowerShell script file (.ps1)
Next open the Logitech gaming software

and click on the G-Keys and select the blue down-arrow to edit a G-Key

choose "Shortcut" and fill in the name (optional) and the shortcut location (location of the PowerShell script)

make sure that the file location does NOT have space in the name otherwise you get an error
(e.g.: C:\Users\username\Documents\DomoticzKeyboardCommands\AmbilightOn.ps1)
(NOT: C:\Users\username\Documents\Domoticz Keyboard Commands\Ambilight On.ps1
Do the same with your other scripts and G-Keys
Test by pressing the g-keys, if nothing happened and you see an PowerShell command screen with red letters it probably says something like:

(This image have i found on the interwebz because i fixed my error already)
You can fix this by doing the following:
Go to start and type PowerShell

right click on Windows PowerShell (x86) and run as administrator
Type the following command:
Possible values for the -ExecutionPolicy parameter:
– Restricted: The default setting which does not load configuration files or run scripts.
– AllSigned: Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
– RemoteSigned: Requires that all scripts and configuration files downloaded from the Internet be signed by a trusted remote publisher.
– Unrestricted: Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.
– Bypass: Nothing is blocked and there are no warnings or prompts.
– Undefined: Removes the currently assigned execution policy from the current scope, returning the session to the default. This parameter will not remove an execution policy that is set in a Active Directory Group Policy.
and choose A for Yes to All

Now do the same for Windows PowerShell (without (x86) )
and the G-Key should work
Let me know if you have any suggestions or questions
I came up with the following solution:
(disclaimer: this solution enables PowerShell commands to be executed on your computers and MIGHT expose you to security risks, so use at your own risk)

How did I do this:
open your favorite text editor and create a PowerShell script (is made 4)

The script contains the following code: (change your ip address and the idx number to your situation, also this example is to turn the switch On, you can also use the Off command)
Code: Select all
$url="http://xx.xx.xx.xx:8080/json.htm?type=command¶m=switchlight&idx=220&switchcmd=On"
(New-Object System.Net.WebClient).DownloadString("$url");Be sure to save it as a PowerShell script file (.ps1)
Next open the Logitech gaming software

and click on the G-Keys and select the blue down-arrow to edit a G-Key

choose "Shortcut" and fill in the name (optional) and the shortcut location (location of the PowerShell script)

make sure that the file location does NOT have space in the name otherwise you get an error
(e.g.: C:\Users\username\Documents\DomoticzKeyboardCommands\AmbilightOn.ps1)
(NOT: C:\Users\username\Documents\Domoticz Keyboard Commands\Ambilight On.ps1
Do the same with your other scripts and G-Keys
Test by pressing the g-keys, if nothing happened and you see an PowerShell command screen with red letters it probably says something like:

(This image have i found on the interwebz because i fixed my error already)
You can fix this by doing the following:
Go to start and type PowerShell

right click on Windows PowerShell (x86) and run as administrator
Type the following command:
Code: Select all
Set-ExecutionPolicy RemoteSigned– Restricted: The default setting which does not load configuration files or run scripts.
– AllSigned: Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
– RemoteSigned: Requires that all scripts and configuration files downloaded from the Internet be signed by a trusted remote publisher.
– Unrestricted: Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.
– Bypass: Nothing is blocked and there are no warnings or prompts.
– Undefined: Removes the currently assigned execution policy from the current scope, returning the session to the default. This parameter will not remove an execution policy that is set in a Active Directory Group Policy.
and choose A for Yes to All

Now do the same for Windows PowerShell (without (x86) )
and the G-Key should work
Let me know if you have any suggestions or questions