Last week I made a post about the connection between the Logitech LCD and
the Steemit blockchain. Here
A few days ago @techtek presented me his project 'Blinkit' on discord, and he asked me to make it possible to use Logitech Keyboards with RGB Backlight too.
We talked about how the idea of a flashing keyboard can be integrated into his existing project.
Blinkit itself is written in VB.NET/VBScript. So I had to find a way to get this working.
Here are the things I have used to solve this task:
The problem is that the LogitechLedEnginesWrapper.dll is not coded in a vb.net
compatible format. So if I want to load this DLL in vbs it does not run and gives an error.
dim dll
set dll = CreateObject("LogitechLedEnginesWrapper.dll")
I created ,in VB.NET, a DLL that imports the functions needed from the Original .dll so VBScript can read the new dll.
To accomplish that follow these steps:
(You can rename the ComClass1 if you like)
At first there is a warning saying:
'Microsoft.VisualBasic.ComClassAttribute' is specified for class 'ComClass1' but 'ComClass1' has no public members that can be exposed to COM; therefore, no COM interfaces are generated.
Don't get confused by that. We will fix it later.
To import native dll files we need to use the System.Runtime.InteropServices library.
If this function gets called the keyboard starts flashing but the programm goes on and does not wait
until the keyboard stopped. So we have to wait as long as we want the effect to go on.
After the effect is gone we disconnect our application from the keyboard with the
LogiLedShutdown function (line 54)
Now we have to add a "Strong name" to our dll. This is done by rightclicking the project.
and go to properties.
This should pop up.
On the left go to "Signing" and tick the box "Sign the assembly"
In the drop down menu choose <new..>
Choose a name and disable the "protect my keyfile with a password".
Now you can close the window in the tab menu.
If not done yet save the project. Go to file -> save all.
Make sure that the marked tick box is ticked^^
After that being done. We can build our dll file by rightclicking the project like we did last time
and hit build. You will get an error if Visual Studio is not opened with administrator privileges!
Now we can close Visual Studio.
Next go to the directory where you saved your project.
(pathtoproject\bin\Debug) There you can find your .dll file.
As the next step we have to register this dll to windows.
This is done by the use of the RegAsm.exe found in:
C:\Windows\Microsoft.NET\Framework\v4.0.30319
Open a command prompt and go to this directory.
After that type:
RegAsm.exe pathtoproject\bin\Debug\name.dll /codebase
This registers the dll in windows. If you want to remove the registration type:
RegAsm.exe pathtoproject\bin\Debug\name.dll /u
To check everthing worked open regedit.exe.
There you press Ctrl+f to start a search. Put in there the ClassID from the beginning.
It should show something like this:
There you can see the path where the dll is located.
Create a new file and add .vbs as the format.
Open that file with an editor like Notepad++
and write in there:
dim logi
set logi = CreateObject(LogitechDll.LogitechDll) 'or parameter that is shown in the registry under Class
logi.LogiLed "blue",3000
First we create a new variable called logi. After that we set it as a new object from the dll.
At this point we can access the functions inside the dll.
Then we call the function LogiLed and pass the string that defines the color and the time how
long the effect should be shown.
Make sure the LogitechLedEnginesWrapper.dll is in the same directory as the .vbs file!
If you run this file it should look like this:
You created your own "bridge" between a native dll and VBScript, if you dont want to make everything by yourself you can use the files i build and uploaded!
You can download the project files here.
Blinkit can be downloaded here.
I hope everything is easy to follow, and if anything is unclear please let me know in the comments or on the github project page.