Can I write to a file through the Logitech Lua api? - c#

The reason I want to do this is because I am trying to light a single key through a script. I want to invoke the script through Logitech lua api. the functionality will act as a feedback response.
fx I have create a macro for the G1 button and I want to light that specific button when the macro is active and turn it off when it isn't.
My solution is that I have created a C# script that repeatedly looks in a text file. If the text file has written "on" in it, it turns on the LED etc.
now I just need a way to update the text file through the logitech Lua API.
but it does not seem as I am allowed to write to a file.
I have tried with the following code to write to the text file:
file = io.open("D:\\creative\\programming\\C#\\logi\\test.txt", "w")
file:write("on")
file:close()
but without any luck as I get the error message:
[string "LuaVM"]:35: attempt to index a nil value (global 'io') Line
Number:1
------------------------- extra to explain comment ----------------------------
let say that I have actions inside applications in parenthesis and actions without effect in italic:
assume it is off to begin: the "->" acts as a g1 press and shows the sate of the toggle after:
-> on -> off
-> (on) -> (on) -> on ========> -> on -> off -> on
because the g1 presses while the loop is running and the application window is focused are queued and will only take effect while outside the application

io library is absent, so you can not write to a file from Lua code.
But you can execute external program (for example, any exe-file) by creating a macro (of type "shortcut") and invoking it with PlayMacro(macro_name) from Lua code.
Just write the external program in C#.

Related

Finding some terminologies for doing R&D

I am here because I have a program and some features in my mind.
But I am not sure what these features are called in programming terms. So I am unable to even do a proper google search regarding the same. I am keen to identify what this is called, so I can progress my Analysis and Research.
I have developed a program, with C# and Windows Forms. Currently it interfaces with YouTube API and monitors the chat. I am also raising some events, when chat messages arrive and when the message follows a certain format/syntax. Everything is working fine so far.
What I want to do is:
If someone using my software, who has access to just the binaries. But want to write their own logic, which handles some of the events I am raising. How do they do that?
I want the user to write their own program/class, put it in a specific folder. I will expect it to have a Start() and End() method. Inside the methods, they can write the code to subscribe to any event of their choice and do what they need to.
I already have written code inside my main loop, which will loop through the folder which is supposed to contain the user programs, and tries to invoke the Start/End method of their programs/classes.
For me, as the original author of the project, I can just go ahead and start writing the code inside the folder. Once I build and execute. Everything works fine. The main program triggers the Start/End inside the program/class that I added. And the events are also handled fine.
But how about someone using my software, who wants to handle it's events, without having to re-compile my code. How do they do that?
You have the following options
Option 1
Create a template project with all required references and a code file (.cs) with the Start() / End() methods.
Add comments to the start() / end() methods or add a code sample of how they can work with the additional events.
The project should compile fine without any source code for your main project.
If you expect the users to use Visual Studio Code, give them instructions to compile using VS code.
If they are going to use any text editor, you need to provide them with a msbuild command line to compile their code.
Finally they can put the .cs code file in the specific folder along with your main project binary and try it out.
Option 2
The above option will work only if your users are also programmers.
If they are semi-techies, you could provide a simpler format for them to provide the additional events.
For example, create a json or xml format where they can specify the event name and how they want to handle it - either a script or choose from some options. For example -
{
"myevents": [
{
"event": "chatUpvote",
"handler": "ThankYouHandler"
},
{
"event": "chatDownvote",
"handler": "TellMeMoreHandler"
}]
}

Can I instruct a console application to consider the console start position one tab to the right?

I'm working at the moment with a PowerShell script calling a C# console application, but I'm curious if there's a general solution.
Basically, my script loops over some files, prints out something for each one, and calls my program. Everything works, but what I'd like to do is have my console program's output show up indented by one tab stop. Right now I've managed that manually (just "hard-coding" the tab stop in my Console.WriteLine() statements), but that's hardly ideal from a maintenance standpoint, since sometimes this program will be run on its own.
An example of what I'm looking for is
powershell output file #1
c# program output
c# program output
powershell output file #2
c# program output
c# program output
Would it help to use a dedicated logger class? It would also be slick to do different colors for the called program, but I'd settle for a non-intrusive way to do indentation. In particular, a solution that avoids the necessity of editing the called program (e.g. for third party code I don't have source for) would be preferred.
Here's a pure PS solution:
# This assumes all output you care about is via stdout
$yourProgramOutput = yourprogram.exe
$yourProgramOutput | foreach-object {
write-host "`t$_"
}
or as a one-liner:
yourprogram | % { write-host "`t$_"}

Edit Windows Context Menu in the C#

I would like a particular type of file (eg. Namefile.ext2) read all the names preceded by a #
Sample contents of the file:
#nameone
#nametwo
#namethree
When I click the right mouse button on the ext2 file extension beyond the standard options (like: open, properties, etc ...) I would like to be:
contents of the file > nameone
nametwo
namethree
Then, select the item (eg. nameone) pass this parameter to my program running in the background / or services
Do you need to modify the registry somehow? I will be grateful for tips on how to achieve the desired effect.
What you are asking about is called 'shell extension'. Basically it requires some knowledge of COM objects programming, but .NET made things a bit easier in that matter.
Shortly: you have to develop a piece of code which will reads the file and generates menu items dynamically (which may be tricky but possible). That code needs to be registered in the system as COM object.
Before it starts working you have to associate file extension with COM object you created.
Perhaps this article can explaint it a bit more:
http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus

How to Show the Content of a Variable Which is in a Class Library In A Form Or Console?

I have a C# solution which contains a project and a class library written by somebody else. The class library gets GPS data via wifi. The project shows the processed data on a map. Now, I want to see the contents of some variables in the class library in real time for the sake of debugging.
I tried to use
System.Diagnostics.Debug.Write(value)
without success. It seems it does not do anything.
Also I tried "MessageBox.Show(value.ToString())" which was good but it stopped the wifi reading and interrupted the program as I needed to press OK button each time that it showed up.
Moreover, I added a windows form (which contained a textBox) to the class library to print the data in the textBox, however, when I wrote:
Form1.textBox1.Text = value.ToString()
It gives me this error:
Error 3 'MapNMEA.Form1.textBox1' is inaccessible due to its protection level C:\Users\john\Documents\Visual Studio 2010\Projects\new ver of map purecom\MapExplorer\MapExplorer\MapNMEA\MapNMEA\SerialPort.cs 184 27 MapNMEA
"MapNMEA" is the name of the class library. Also "MapExplorer" is the name of both solution and the project. "SerialPort.cs" is a file inside the class library in which I wrote the above code.
My question is how to show the content of those variable (they are 3,4 variables) in real time and this act should not stop the wifi reading. I need to do this as an electrician who does not know much about programming wants to check whether a GPS device sends the data to my computer correctly or not.
UPDATE 1: Actually I noticed that System.Diagnostics.Debug.Write(value) is working but as there was too many warning messages showing up in the debug window, I did not noticed it. Now, if somehow I could remove (or hide) other (warning) messages, I would see only my desired output. Do you know?
Debug.Write should be fine if you attach a listener first (Debug.Listeners.Add( new _a_listener_type() )).
Also, you should probably be aware of the AutoFlush property on the Debug class which determines whether or not Flush is automatically called.
Debug.Write should work - by default it will write to the 'Debug' window in Visual Studio if you have the debugger attached. Are you sure you're looking in the right place?
If you want to use the form approach, you need to keep track of the instance of the form which is open, and give it a public method. For example:
public void WriteDebug(string message) {
TextBox1.Text += message + Environment.NewLine;
}
Then you can call formInstance.WriteDebug(message);.
Do you run debug build? Also your code with textbox does not work, because textBox1 is non-public
I think you may not be searching the right location: Is there something preventing you from debugging on a PC first before going to a target? If not, the you should probably use the traditional way: put spies on variables, use your IDE (Visual Studio) to watch them and so on.
If you actually NEED to run on target without advanced debug tools, then you might want to take a look at some easier solutions:
log them to a text file (append or replace, whatever you need), then have a viewer opened at hand
make another non-modal form with a textbox, and call a form2.writeDbgTextBox(String) every time you need to refresh
Be sure to remove this code on release (eg. by putting them in a #if DEBUG section)
And whatever happens, DO NOT try to write to an existing Message box! they are made to pop up and close, not to interact with your code.

How to write a vb.net code to compile C/C++ programs?

I'm trying to make a vb.net application that has got 2 textboxes, 7 radio buttons and 2 buttons(one named compile and the other 'run'). How can I load the content of a C/C++(or any programming language) file into the 1st textbox and on clicking the compile button, i should be able to show the errors or the C/C++ program in the 2nd textbox. On clicking Run, I should be able to show the output in the 2nd textbox. In short, I want to use the 2nd textbox as a terminal/console. The radio buttons are 4 selecting the language C or C++ or python or C# or java or perl or vb.
Are the compilers of all these languages present in .net? If so how can I call them?
Look at the System.IO namespace for clues as to how you go about loading the contents of a file into a text box. In particular, the File class.
System.IO.File Class
Look at the System.Diagnostics namespace for clues as to how to go about launching a process and capturing the output. In particular, the Process class.
System.Diagnostics.Process Class
This SO page...
Capturing the Console Output in .NET (C#)
... will give you some more info around capturing console output.
Compiling can be done by calling cl.exe which comes with Visual Studio. Of course you could also use GCC instead.

Categories

Resources