|
using System;
namespace ConsoleApplication10 {
class Program {
static void Main( string[] args ) {
double[] trace = new double[] {
47.92370605, 44, 49, 46.31715393, 44.98129654, 46.17653275,
78, 73, 82, 63, 69, 41.72979736, 41.13000488, 41.49586487,
37, 40, 30, 40.79894257, 40.65593719, 41.37298584, 39.13498688,
55, 51, 60, 39.3440094, 38.51491547, 42, 35.12589264 };
double low = trace[ 0 ];
double previous = trace[ 0 ];
double peak = trace[ 0 ];
for ( int i = 1; i < trace.Length; i++ ) {
double current = trace[ i ];
if ( current > previous ) {
peak = current;
} else {
if ( current < previous ) {
if ( ( peak - low >= 6.0 ) && ( peak - current >= 6.0 ) ) {
Console.WriteLine( $"Peak: {peak} @{i}" );
low = peak = current;
}
}
}
previous = current;
}
Console.ReadKey();
}
}
}
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi Gerry,
This is a smashing bit of code and works great on the sample data provided. However, if you change p10 value 63 to 64, we lose peak 11 value 69 as expected but we also lose peak 24 at level 60.
Many thanks for the great code it gives me food for thought
Nigel
|
|
|
|
|
One works with the samples provided.
Your "requirements" keep changing.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
It's not as much as a question, but more a set of specs. My interest in the question is gone suddenly
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
New here. New to coding.
I am looking to make a program which causes a picture to pop up (perhaps in a WindowsForm) when a certain word ("dog", for instance) is typed by the end user.
So, say someone is writing a story in Word and they type the word "dog" as part of their story. How could I make a picture of a dog pop up for a few seconds every time the word is typed?
I think it has something to do with KeyPressEvenHandler, but I have tried to find many sources for this, and each time I find an example, there are about 20 errors, even when I follow the directions to the letter.
It is very frustration, but I will figure it out, hopefully with someone's help here.
Thanks in advance for any help you can provide. Also, If someone has time to give me some code to get started that will actually run, that would be very helpful. Only been studying C# for about a month, and I learn best from example.
|
|
|
|
|
This is far more complex than you realize.
The events you see in the form are useless to you because your form won't have the input focus if the user is typing in Word.
To do something like that requires the use of a global keyboard hook. This is a rather advanced topic, not for the newcomer to programming!! But, if you want to see examples, just Google for "C# global keyboard hook".
|
|
|
|
|
On the contrary, I had no doubt that it was difficult. And I also realize that it is a very ambitious attempt for a noob. But your suggestion for Google is precisely what I needed. Thank you very much for taking the time to answer. I was having a hard time searching for the keywords that would lead me to the answer. I'll educate myself in due time.
Meanwhile, if anyone else can offer an example, that would be cool, too.
Thanks again, Mr. Kreskowiak!
|
|
|
|
|
Big picture: if you are "New to coding," I think pursuing something this complex ... inter-op with Word ... is not a good strategy to maximize what you learn. Why not take one of the many extended Rich TextBoxes for WinForms, and use that for your editing control ?
To tango with Word, you need to research, and learn to use, inter-operation between MS Word and C#. Lots of resources on this: search here, and on the net [^]
Then, you need to determine what are the possibilities for intercepting Key Events in MS Word from C#: can you install/hook your own KeyDown handler from C# into the running instance of MS Word ? , [^], For all I know, this may require writing a Word add-in.
If you get that far, then you have to implement your own equivalent to an auto-completion facility: that's not hard: if you ask a specific question on that, I will respond with code.
If you can't get MS Word key events in C# as described above: then you are going to need some form of hook, as Dave K. mentions.
If you do get a hook working, then every keystroke in Word is going to require a call though the hook to your code: I suspect that will have a real impact on performance, depending on your hardware, memory, etc.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
Thank for such a detailed reply. It should certainly set me in the right direction.
|
|
|
|
|
As a novice, I would strongly suggest that you "shelve" this project for a while, and get some solid experience with "normal" C# before you think about considering this.
Global C# hooks are not trivial at all, and a very small mistake in your code can seriously destabilize your whole system: they have to "hook" directly into low level stuff and bypass the "usual protection" the OS provides to prevent one app from affecting another. I would recommend good, solid, regular, air-gapped backups before each attempt to do this: you could bugger your system to the point of reformat and reinstall very, very easily...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If you create a "context / scenario", it may be easier to move forward.
If you start with a "large" textbox, you can obviously type in some "words".
The "textbox" allows you to determine "where" the cursor is in the textbox, if a "word" is selected, and so forth.
c# - How to get current word at the Caret position from a String(TextBox) which is having SPACE and ENTER key? - Stack Overflow
"Keyboard hooks" require you to practically create your own "word processor"; when all you want to do is "parse some text".
Google "text handling"/ textboxes instead of "hooks".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Let's say I have a class myClass and I create two object of that class called MyObject1 and MyObject2. Can I do something so that MyObject1 and MyObject2 can be casted into ints like this:
(int)MyObject1 // I want this to compile and the expression should equate 1
(int)MyObject2 // I want this to compile and the expression should equate 2
|
|
|
|
|
I think you're looking for this[^].
For example:
public class MyObjectClass
{
private string internalValue = "Something";
public static implicit operator int(MyObjectClass value)
{
return int.Parse(value.internalValue);
}
public static implicit operator MyObjectClass(int value)
{
return new MyObjectClass(value);
}
private MyObjectClass()
{
}
public MyObjectClass(int value)
{
internalValue = value.ToString();
}
}
And to use it:
MyObjectClass x = new MyObjectClass(201);
int value = (int)x;
|
|
|
|
|
Yes, thanks, this looks like a very good solution.
|
|
|
|
|
So, before we overcomplicate things, why aren't you just putting those objects into an array?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
DaveK's post here is an excellent lesson in use of 'implicit operators: I up-voted it, and, so should you !
I wonder why you want to use such a technique, involving casting, boxing, when all you need is a simple integer field, or property, in the class ?
public class MyClass
{
public int Id { private set; get; }
public MyClass(int id)
{
Id = id;
}
}
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
That's what I use today. Basically, I have portable products (with ARM processors inside) with registers that I can read from and write to with a PC-application:
uint32 readReg(uint address)
void writeReg(uint address, uint newValue)
In the beginning, I used enum that I casted into uint for the addresses, but then I found that I wanted to share some addresses across products but I couldn't figure out a way to inherit enum. So I created a class instead (see for example java - Simulate a class of type enum - Stack Overflow ) but now I wasn't able to cast into uint anymore, which I think is a cleaner solution.
|
|
|
|
|
in C# how can i get my app to start on open if i remove the start function, say i dont want to command it to start, but actually start as soon as i execute the exe file.
|
|
|
|
|
Do you want to try that again? This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So stop trying to type the minimum words you can get away with and help us to help you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
i have a system that monitors the contents of a file. File checker created in C#, with a start and stop function, i want to use task scheduler to startup the app and stop it, but it cant start the actual file monitoring process, is the a way in which i could remove the start and stop function so that the application starts monitoring the files immediately its executed and stops when it is closed .
|
|
|
|
|
How do you expect us to know that, given that we can't see your code at all and have no idea how you have written it?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
All programs start as soon as you execute their exe files. Your question makes no sense.
|
|
|
|
|
Did you by accident write a windows service? If yes, delete the source-code; you shouldn't be writing those.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
is it possible to create a class that schedules a program to start and stops at specific times of the day, say it run from 00;00 to 23;59 every day
|
|
|
|
|
Within your app, yes - but it will only work if your app is running at the time.
If it isn't, you can't use a class to do that, because all class instances are destroyed at the end of the app.
You can however run an app at a specific time each day: Task Scheduler (Windows)[^] will let you do that pretty easily.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|