0

I'm currently working on a Program, that presses buttons for me. I'm working on WPF but I already finished my design in XAML, now I need some C# code.

I have a TextBox that should handle all the SendKeys input. I want to extend it's functionality by providing some CMD-like arguments. The problem is, I don't know how. ;A; For example:

W{hold:500}{wait:100}{ENTER}

This is a example line that I'd enter in the textbox. I need 2 new functions, hold and wait.

  1. The hold function presses and holds the previous key for the specified time (500 ms) and then releases the button.
  2. The wait function waits the specified time (100ms).

I know I could somehow manage to create this function but it would end up being not user editable. That's why I need these arguments.

HitomiTenshi
  • 514
  • 2
  • 6
  • 20
  • Are you asking how to create a parser? – GrandmasterB Mar 22 '12 at 18:06
  • Yea I guess so, if parser means one of those predefined functions, then yea. I gotta say I'm a bit new to C#. – HitomiTenshi Mar 22 '12 at 18:25
  • 1
    Its still not very clear what you are asking here. What is the *exact* problem you are encountering? Do you not know how to make the system wait for a time? Or is the trouble extracting and identifying the commands that are in the text box? – GrandmasterB Mar 22 '12 at 18:57
  • Extracting and identifying the commands is my problem! Sorry that I was so unclear. – HitomiTenshi Mar 22 '12 at 19:08
  • You might be interested in this SO question about [how to generate key press events in WPF](http://stackoverflow.com/a/1646568/302677) – Rachel Mar 22 '12 at 19:32

1 Answers1

0

You're trying to 'parse' the text in the text box. The simplest way is to read each character in the text, one by one, and look for '{'. Once found, everything after that up until the '}' is the command. You can then do the same for that extracted command, splitting it at the ':' to get the parameters to the command. Everything not within a '{}' is then a literal key you send.

There are far more sophisticated ways of writing parsers, but for what it sounds like you are doing, the above would be a good first step to get you familiar with processing text.

GrandmasterB
  • 3,396
  • 1
  • 23
  • 22
  • Thanks! After lots of research I have found a good solution. I'll just use the `split` function on my string, save everything in an array and then process it through an `foreach` loop. – HitomiTenshi Mar 22 '12 at 22:24