-1

I am looking for a code that will press any keyboard key every 50 seconds, lets say the key is the number 5 key.

Just make sure that it wont just type 5, I want it to press the key itself.

EDIT: i just want it to press any keyboard key thats all. like if its shift or capslock or whatever

Leonardo
  • 10,737
  • 10
  • 62
  • 155
Bxcb Sbdsb
  • 105
  • 1
  • 2
  • 5

5 Answers5

5

I am assuming you want to achieve this programmatically.

If this is the case you can use:

    SendKeys.Send({NUMPAD5});
    SendKeys.Send({HOME});

And so on. For the timer part:

    Timer timer = new Timer();
    timer.Tick += new EventHandler(timer_Tick);     // Everytime timer ticks, timer_Tick will be called
        timer.Interval = (1000) * (50);             // Timer will tick every 50 second
        timer.Enabled = true;                       // Enable the timer
        timer.Start();                              // Start the timer

    void timer_Tick(object sender, EventArgs e)
    {
        SendKeys.Send({NUMPAD5});
    }
Yakup Ünyılmaz
  • 404
  • 3
  • 11
2

Look at the SendKey class. MSDN

Hamlet Hakobyan
  • 32,965
  • 6
  • 52
  • 68
2

You could use SendKey in combination with a Timer.

Ralf de Kleine
  • 11,464
  • 5
  • 45
  • 87
0

Software can simulate a key press by various methods, ie, mimic what would happen when the key was pressed. What it cannot do is press the key. You would need to create a robot that would press the key every so often.

Can you provide the context in which you are trying to achieve this. There may be better ways to do this.

Kami
  • 19,134
  • 4
  • 51
  • 63
0
        int countTypeA = 0;
        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.A:
                    ++countTypeA;
                    Console.WriteLine(countTypeA.ToString());
                    break;
            }
        }
spajce
  • 7,044
  • 5
  • 29
  • 44