Click here to Skip to main content
15,911,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to make a simple program that will take a very long string with about 100 words, and split them at spaces. My problem is that when I turn off my timer it keeps typing and won't turn off. Any ideas?

C++
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SpamTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            string s = "text here to type text text text";
            // Split string on spaces.
            // This will separate all the words.

            string[] words = s.Split(' ');
            foreach (string word in words)
            {
                SendKeys.Send(word);
                SendKeys.Send("{ENTER}");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
Posted
Comments
Tim Groven 13-Mar-12 16:12pm    
Can I see the timer creation code? What is the interval set at?
Sergey Alexandrovich Kryukov 13-Mar-12 17:52pm    
Don't you think the whole idea is helplessly wrong?
--SA
Shahin Khorshidnia 13-Mar-12 17:38pm    
No, I am runing it and it's working.
Maybe the button2 lost the event method. Ensure that its delegate method is set.
Sergey Alexandrovich Kryukov 13-Mar-12 17:51pm    
Both ideas looks very bad: using a timer and using SendKeys. Why would you do it? You should not do it. If you need a good advice, you should explain more on how chat works and what do you have to pick up text flow from it.
--SA
morhen77 14-Mar-12 3:56am    
Is your aim to get one word to be written out each timer tick? Cuz now, each time the timer fires it will go thru all the words as fast as possible. But then again, I can't phantom the use of either...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900